0 00:00:00,0 --> 00:00:05,0 Downloaded from git.ir 1 00:00:01,190 --> 00:00:04,100 hi my name is Mohamad ani and i'm super 2 00:00:04,100 --> 00:00:04,110 hi my name is Mohamad ani and i'm super 3 00:00:04,110 --> 00:00:05,990 hi my name is Mohamad ani and i'm super excited to be your instructor in this 4 00:00:05,990 --> 00:00:06,000 excited to be your instructor in this 5 00:00:06,000 --> 00:00:07,430 excited to be your instructor in this three hour course you're going to learn 6 00:00:07,430 --> 00:00:07,440 three hour course you're going to learn 7 00:00:07,440 --> 00:00:09,020 three hour course you're going to learn everything you need to get started with 8 00:00:09,020 --> 00:00:09,030 everything you need to get started with 9 00:00:09,030 --> 00:00:12,200 everything you need to get started with SQL or sequel first so I'm gonna give 10 00:00:12,200 --> 00:00:12,210 SQL or sequel first so I'm gonna give 11 00:00:12,210 --> 00:00:14,089 SQL or sequel first so I'm gonna give you a three minute introduction to SQL 12 00:00:14,089 --> 00:00:14,099 you a three minute introduction to SQL 13 00:00:14,099 --> 00:00:15,709 you a three minute introduction to SQL then we're going to install the 14 00:00:15,709 --> 00:00:15,719 then we're going to install the 15 00:00:15,719 --> 00:00:18,560 then we're going to install the necessary tools and write our first SQL 16 00:00:18,560 --> 00:00:18,570 necessary tools and write our first SQL 17 00:00:18,570 --> 00:00:21,170 necessary tools and write our first SQL query this course is ideal for anyone 18 00:00:21,170 --> 00:00:21,180 query this course is ideal for anyone 19 00:00:21,180 --> 00:00:23,450 query this course is ideal for anyone who wants to learn SQL from scratch but 20 00:00:23,450 --> 00:00:23,460 who wants to learn SQL from scratch but 21 00:00:23,460 --> 00:00:25,250 who wants to learn SQL from scratch but also anyone with some basic knowledge 22 00:00:25,250 --> 00:00:25,260 also anyone with some basic knowledge 23 00:00:25,260 --> 00:00:27,950 also anyone with some basic knowledge who wants to fill in the missing gaps by 24 00:00:27,950 --> 00:00:27,960 who wants to fill in the missing gaps by 25 00:00:27,960 --> 00:00:29,509 who wants to fill in the missing gaps by the end of this course you'll be able to 26 00:00:29,509 --> 00:00:29,519 the end of this course you'll be able to 27 00:00:29,519 --> 00:00:32,450 the end of this course you'll be able to retrieve insert update and delete data 28 00:00:32,450 --> 00:00:32,460 retrieve insert update and delete data 29 00:00:32,460 --> 00:00:34,970 retrieve insert update and delete data in databases will talk about tables 30 00:00:34,970 --> 00:00:34,980 in databases will talk about tables 31 00:00:34,980 --> 00:00:37,340 in databases will talk about tables relationships different types of joins 32 00:00:37,340 --> 00:00:37,350 relationships different types of joins 33 00:00:37,350 --> 00:00:40,160 relationships different types of joins sub queries regular expressions are much 34 00:00:40,160 --> 00:00:40,170 sub queries regular expressions are much 35 00:00:40,170 --> 00:00:41,900 sub queries regular expressions are much much more these are the essential 36 00:00:41,900 --> 00:00:41,910 much more these are the essential 37 00:00:41,910 --> 00:00:44,000 much more these are the essential concepts that every software developer 38 00:00:44,000 --> 00:00:44,010 concepts that every software developer 39 00:00:44,010 --> 00:00:46,340 concepts that every software developer or data scientist must know this SQL 40 00:00:46,340 --> 00:00:46,350 or data scientist must know this SQL 41 00:00:46,350 --> 00:00:48,740 or data scientist must know this SQL force is packed with tons of exercises 42 00:00:48,740 --> 00:00:48,750 force is packed with tons of exercises 43 00:00:48,750 --> 00:00:50,540 force is packed with tons of exercises that help you both learn and remember 44 00:00:50,540 --> 00:00:50,550 that help you both learn and remember 45 00:00:50,550 --> 00:00:53,600 that help you both learn and remember the SQL syntax also there's a table of 46 00:00:53,600 --> 00:00:53,610 the SQL syntax also there's a table of 47 00:00:53,610 --> 00:00:55,490 the SQL syntax also there's a table of content below this video so you can 48 00:00:55,490 --> 00:00:55,500 content below this video so you can 49 00:00:55,500 --> 00:00:58,130 content below this video so you can quickly jump to specific tutorials now 50 00:00:58,130 --> 00:00:58,140 quickly jump to specific tutorials now 51 00:00:58,140 --> 00:01:04,399 quickly jump to specific tutorials now let's jump in and get started let's 52 00:01:04,399 --> 00:01:04,409 let's jump in and get started let's 53 00:01:04,409 --> 00:01:05,990 let's jump in and get started let's start the course with a quick overview 54 00:01:05,990 --> 00:01:06,000 start the course with a quick overview 55 00:01:06,000 --> 00:01:08,210 start the course with a quick overview of databases what they are and how we 56 00:01:08,210 --> 00:01:08,220 of databases what they are and how we 57 00:01:08,220 --> 00:01:10,820 of databases what they are and how we use them a database is a collection of 58 00:01:10,820 --> 00:01:10,830 use them a database is a collection of 59 00:01:10,830 --> 00:01:13,370 use them a database is a collection of data stored in a format that can easily 60 00:01:13,370 --> 00:01:13,380 data stored in a format that can easily 61 00:01:13,380 --> 00:01:15,679 data stored in a format that can easily be accessed in order to manage our 62 00:01:15,679 --> 00:01:15,689 be accessed in order to manage our 63 00:01:15,689 --> 00:01:17,420 be accessed in order to manage our databases we use a software application 64 00:01:17,420 --> 00:01:17,430 databases we use a software application 65 00:01:17,430 --> 00:01:18,230 databases we use a software application called 66 00:01:18,230 --> 00:01:18,240 called 67 00:01:18,240 --> 00:01:21,859 called database management system or DBMS we 68 00:01:21,859 --> 00:01:21,869 database management system or DBMS we 69 00:01:21,869 --> 00:01:23,510 database management system or DBMS we connect to a DBMS and give it 70 00:01:23,510 --> 00:01:23,520 connect to a DBMS and give it 71 00:01:23,520 --> 00:01:26,060 connect to a DBMS and give it instructions for querying or modifying 72 00:01:26,060 --> 00:01:26,070 instructions for querying or modifying 73 00:01:26,070 --> 00:01:28,399 instructions for querying or modifying data the DBMS will execute our 74 00:01:28,399 --> 00:01:28,409 data the DBMS will execute our 75 00:01:28,409 --> 00:01:31,429 data the DBMS will execute our instructions and send results back now 76 00:01:31,429 --> 00:01:31,439 instructions and send results back now 77 00:01:31,439 --> 00:01:32,990 instructions and send results back now we have several database management 78 00:01:32,990 --> 00:01:33,000 we have several database management 79 00:01:33,000 --> 00:01:34,969 we have several database management systems out there and these are 80 00:01:34,969 --> 00:01:34,979 systems out there and these are 81 00:01:34,979 --> 00:01:36,999 systems out there and these are classified into two categories 82 00:01:36,999 --> 00:01:37,009 classified into two categories 83 00:01:37,009 --> 00:01:40,010 classified into two categories relational and non-relational also 84 00:01:40,010 --> 00:01:40,020 relational and non-relational also 85 00:01:40,020 --> 00:01:42,950 relational and non-relational also called no sequel in relational databases 86 00:01:42,950 --> 00:01:42,960 called no sequel in relational databases 87 00:01:42,960 --> 00:01:45,679 called no sequel in relational databases we store data in tables that are linked 88 00:01:45,679 --> 00:01:45,689 we store data in tables that are linked 89 00:01:45,689 --> 00:01:47,929 we store data in tables that are linked to each other using relationships that's 90 00:01:47,929 --> 00:01:47,939 to each other using relationships that's 91 00:01:47,939 --> 00:01:50,389 to each other using relationships that's why we call this databases relational 92 00:01:50,389 --> 00:01:50,399 why we call this databases relational 93 00:01:50,399 --> 00:01:53,270 why we call this databases relational databases each table stores data about a 94 00:01:53,270 --> 00:01:53,280 databases each table stores data about a 95 00:01:53,280 --> 00:01:55,700 databases each table stores data about a specific type of object like customer 96 00:01:55,700 --> 00:01:55,710 specific type of object like customer 97 00:01:55,710 --> 00:01:59,870 specific type of object like customer product order and so on SQL or sequel is 98 00:01:59,870 --> 00:01:59,880 product order and so on SQL or sequel is 99 00:01:59,880 --> 00:02:01,999 product order and so on SQL or sequel is the language that we use to work with 100 00:02:01,999 --> 00:02:02,009 the language that we use to work with 101 00:02:02,009 --> 00:02:04,010 the language that we use to work with these relational database management 102 00:02:04,010 --> 00:02:04,020 these relational database management 103 00:02:04,020 --> 00:02:07,340 these relational database management systems it looks like this we use SQL to 104 00:02:07,340 --> 00:02:07,350 systems it looks like this we use SQL to 105 00:02:07,350 --> 00:02:09,979 systems it looks like this we use SQL to query or modify our data in this course 106 00:02:09,979 --> 00:02:09,989 query or modify our data in this course 107 00:02:09,989 --> 00:02:11,240 query or modify our data in this course we are going to learn everything about 108 00:02:11,240 --> 00:02:11,250 we are going to learn everything about 109 00:02:11,250 --> 00:02:13,280 we are going to learn everything about this powerful language 110 00:02:13,280 --> 00:02:13,290 this powerful language 111 00:02:13,290 --> 00:02:14,839 this powerful language now there are many different relational 112 00:02:14,839 --> 00:02:14,849 now there are many different relational 113 00:02:14,849 --> 00:02:16,280 now there are many different relational database management systems out there 114 00:02:16,280 --> 00:02:16,290 database management systems out there 115 00:02:16,290 --> 00:02:19,459 database management systems out there some of the most popular ones are MySQL 116 00:02:19,459 --> 00:02:19,469 some of the most popular ones are MySQL 117 00:02:19,469 --> 00:02:22,220 some of the most popular ones are MySQL sequel server by Microsoft and Oracle 118 00:02:22,220 --> 00:02:22,230 sequel server by Microsoft and Oracle 119 00:02:22,230 --> 00:02:24,949 sequel server by Microsoft and Oracle but of course there are plenty more each 120 00:02:24,949 --> 00:02:24,959 but of course there are plenty more each 121 00:02:24,959 --> 00:02:26,630 but of course there are plenty more each database management system has a 122 00:02:26,630 --> 00:02:26,640 database management system has a 123 00:02:26,640 --> 00:02:29,089 database management system has a different flavor of SQL but all these 124 00:02:29,089 --> 00:02:29,099 different flavor of SQL but all these 125 00:02:29,099 --> 00:02:31,220 different flavor of SQL but all these implementations are very similar and are 126 00:02:31,220 --> 00:02:31,230 implementations are very similar and are 127 00:02:31,230 --> 00:02:34,309 implementations are very similar and are based on the standard SQL specification 128 00:02:34,309 --> 00:02:34,319 based on the standard SQL specification 129 00:02:34,319 --> 00:02:36,500 based on the standard SQL specification so most of the SQL code that you will 130 00:02:36,500 --> 00:02:36,510 so most of the SQL code that you will 131 00:02:36,510 --> 00:02:38,390 so most of the SQL code that you will learn in this course will work with any 132 00:02:38,390 --> 00:02:38,400 learn in this course will work with any 133 00:02:38,400 --> 00:02:40,550 learn in this course will work with any database management system in this 134 00:02:40,550 --> 00:02:40,560 database management system in this 135 00:02:40,560 --> 00:02:42,949 database management system in this course we'll be using MySQL which is the 136 00:02:42,949 --> 00:02:42,959 course we'll be using MySQL which is the 137 00:02:42,959 --> 00:02:45,379 course we'll be using MySQL which is the most popular open source database in the 138 00:02:45,379 --> 00:02:45,389 most popular open source database in the 139 00:02:45,389 --> 00:02:47,449 most popular open source database in the world right now back to this diagram 140 00:02:47,449 --> 00:02:47,459 world right now back to this diagram 141 00:02:47,459 --> 00:02:50,300 world right now back to this diagram what about non-relational databases in 142 00:02:50,300 --> 00:02:50,310 what about non-relational databases in 143 00:02:50,310 --> 00:02:52,640 what about non-relational databases in non-relational databases we don't have 144 00:02:52,640 --> 00:02:52,650 non-relational databases we don't have 145 00:02:52,650 --> 00:02:55,220 non-relational databases we don't have tables or relationships these databases 146 00:02:55,220 --> 00:02:55,230 tables or relationships these databases 147 00:02:55,230 --> 00:02:56,990 tables or relationships these databases are very different from relational 148 00:02:56,990 --> 00:02:57,000 are very different from relational 149 00:02:57,000 --> 00:02:58,909 are very different from relational databases but that's a topic for an 150 00:02:58,909 --> 00:02:58,919 databases but that's a topic for an 151 00:02:58,919 --> 00:03:01,039 databases but that's a topic for an entirely different course what you need 152 00:03:01,039 --> 00:03:01,049 entirely different course what you need 153 00:03:01,049 --> 00:03:03,050 entirely different course what you need to know is that non relational database 154 00:03:03,050 --> 00:03:03,060 to know is that non relational database 155 00:03:03,060 --> 00:03:05,390 to know is that non relational database management systems don't understand 156 00:03:05,390 --> 00:03:05,400 management systems don't understand 157 00:03:05,400 --> 00:03:08,059 management systems don't understand SQL they have their own query language 158 00:03:08,059 --> 00:03:08,069 SQL they have their own query language 159 00:03:08,069 --> 00:03:11,119 SQL they have their own query language so we use SQL to work with relational 160 00:03:11,119 --> 00:03:11,129 so we use SQL to work with relational 161 00:03:11,129 --> 00:03:13,460 so we use SQL to work with relational database management systems now Before 162 00:03:13,460 --> 00:03:13,470 database management systems now Before 163 00:03:13,470 --> 00:03:15,500 database management systems now Before we jump in and install MySQL let me 164 00:03:15,500 --> 00:03:15,510 we jump in and install MySQL let me 165 00:03:15,510 --> 00:03:17,780 we jump in and install MySQL let me clarify something quickly as you talk to 166 00:03:17,780 --> 00:03:17,790 clarify something quickly as you talk to 167 00:03:17,790 --> 00:03:18,559 clarify something quickly as you talk to different people 168 00:03:18,559 --> 00:03:18,569 different people 169 00:03:18,569 --> 00:03:20,420 different people you'll hear two different pronunciations 170 00:03:20,420 --> 00:03:20,430 you'll hear two different pronunciations 171 00:03:20,430 --> 00:03:24,710 you'll hear two different pronunciations of SQL sequel or SQL what is the correct 172 00:03:24,710 --> 00:03:24,720 of SQL sequel or SQL what is the correct 173 00:03:24,720 --> 00:03:27,110 of SQL sequel or SQL what is the correct way well it depends on who you ask 174 00:03:27,110 --> 00:03:27,120 way well it depends on who you ask 175 00:03:27,120 --> 00:03:29,059 way well it depends on who you ask and of course everybody thinks their way 176 00:03:29,059 --> 00:03:29,069 and of course everybody thinks their way 177 00:03:29,069 --> 00:03:30,680 and of course everybody thinks their way of pronouncing this word is the right 178 00:03:30,680 --> 00:03:30,690 of pronouncing this word is the right 179 00:03:30,690 --> 00:03:32,420 of pronouncing this word is the right way but here's a little history about 180 00:03:32,420 --> 00:03:32,430 way but here's a little history about 181 00:03:32,430 --> 00:03:35,030 way but here's a little history about this language SQL was originally 182 00:03:35,030 --> 00:03:35,040 this language SQL was originally 183 00:03:35,040 --> 00:03:37,849 this language SQL was originally developed at IBM in the 70s and back 184 00:03:37,849 --> 00:03:37,859 developed at IBM in the 70s and back 185 00:03:37,859 --> 00:03:40,039 developed at IBM in the 70s and back then it was initially called sequel 186 00:03:40,039 --> 00:03:40,049 then it was initially called sequel 187 00:03:40,049 --> 00:03:42,469 then it was initially called sequel short for structured English query 188 00:03:42,469 --> 00:03:42,479 short for structured English query 189 00:03:42,479 --> 00:03:44,629 short for structured English query language but they changed the acronym to 190 00:03:44,629 --> 00:03:44,639 language but they changed the acronym to 191 00:03:44,639 --> 00:03:47,360 language but they changed the acronym to SQL because sequel was the trademark of 192 00:03:47,360 --> 00:03:47,370 SQL because sequel was the trademark of 193 00:03:47,370 --> 00:03:49,849 SQL because sequel was the trademark of an airplane company so to this date 194 00:03:49,849 --> 00:03:49,859 an airplane company so to this date 195 00:03:49,859 --> 00:03:51,740 an airplane company so to this date there has been an argument about what is 196 00:03:51,740 --> 00:03:51,750 there has been an argument about what is 197 00:03:51,750 --> 00:03:53,349 there has been an argument about what is the right way to pronounce this language 198 00:03:53,349 --> 00:03:53,359 the right way to pronounce this language 199 00:03:53,359 --> 00:03:56,119 the right way to pronounce this language generally speaking people in non-english 200 00:03:56,119 --> 00:03:56,129 generally speaking people in non-english 201 00:03:56,129 --> 00:03:57,259 generally speaking people in non-english speaking countries 202 00:03:57,259 --> 00:03:57,269 speaking countries 203 00:03:57,269 --> 00:03:59,689 speaking countries call it SQL are used to calling it 204 00:03:59,689 --> 00:03:59,699 call it SQL are used to calling it 205 00:03:59,699 --> 00:04:01,640 call it SQL are used to calling it sequel because it's shorter and sweeter 206 00:04:01,640 --> 00:04:01,650 sequel because it's shorter and sweeter 207 00:04:01,650 --> 00:04:04,280 sequel because it's shorter and sweeter than SQL but if you prefer to call it 208 00:04:04,280 --> 00:04:04,290 than SQL but if you prefer to call it 209 00:04:04,290 --> 00:04:06,289 than SQL but if you prefer to call it SQL as total fine with me I'm not gonna 210 00:04:06,289 --> 00:04:06,299 SQL as total fine with me I'm not gonna 211 00:04:06,299 --> 00:04:08,179 SQL as total fine with me I'm not gonna get mad at you so that's the history 212 00:04:08,179 --> 00:04:08,189 get mad at you so that's the history 213 00:04:08,189 --> 00:04:10,309 get mad at you so that's the history behind this language but what about 214 00:04:10,309 --> 00:04:10,319 behind this language but what about 215 00:04:10,319 --> 00:04:13,580 behind this language but what about MySQL as a software product developers 216 00:04:13,580 --> 00:04:13,590 MySQL as a software product developers 217 00:04:13,590 --> 00:04:15,649 MySQL as a software product developers of this product prefer to call it MySQL 218 00:04:15,649 --> 00:04:15,659 of this product prefer to call it MySQL 219 00:04:15,659 --> 00:04:17,629 of this product prefer to call it MySQL rather than my sequel but they don't 220 00:04:17,629 --> 00:04:17,639 rather than my sequel but they don't 221 00:04:17,639 --> 00:04:20,089 rather than my sequel but they don't mind if we call it my sequel in this 222 00:04:20,089 --> 00:04:20,099 mind if we call it my sequel in this 223 00:04:20,099 --> 00:04:22,180 mind if we call it my sequel in this course I'll be teaching you sequel with 224 00:04:22,180 --> 00:04:22,190 course I'll be teaching you sequel with 225 00:04:22,190 --> 00:04:24,550 course I'll be teaching you sequel with MySQL 226 00:04:24,550 --> 00:04:24,560 MySQL 227 00:04:24,560 --> 00:04:27,500 MySQL hey guys Marsh here I just wanted to let 228 00:04:27,500 --> 00:04:27,510 hey guys Marsh here I just wanted to let 229 00:04:27,510 --> 00:04:28,880 hey guys Marsh here I just wanted to let you know that you really don't have to 230 00:04:28,880 --> 00:04:28,890 you know that you really don't have to 231 00:04:28,890 --> 00:04:30,650 you know that you really don't have to memorize anything in this course because 232 00:04:30,650 --> 00:04:30,660 memorize anything in this course because 233 00:04:30,660 --> 00:04:32,900 memorize anything in this course because I have created a complete cheat sheet 234 00:04:32,900 --> 00:04:32,910 I have created a complete cheat sheet 235 00:04:32,910 --> 00:04:35,150 I have created a complete cheat sheet with summary notes for you you can find 236 00:04:35,150 --> 00:04:35,160 with summary notes for you you can find 237 00:04:35,160 --> 00:04:36,500 with summary notes for you you can find it below this video in the description 238 00:04:36,500 --> 00:04:36,510 it below this video in the description 239 00:04:36,510 --> 00:04:40,130 it below this video in the description box so I have done my best to create the 240 00:04:40,130 --> 00:04:40,140 box so I have done my best to create the 241 00:04:40,140 --> 00:04:42,860 box so I have done my best to create the best possible most comprehensive sequel 242 00:04:42,860 --> 00:04:42,870 best possible most comprehensive sequel 243 00:04:42,870 --> 00:04:44,420 best possible most comprehensive sequel course for you and I would really 244 00:04:44,420 --> 00:04:44,430 course for you and I would really 245 00:04:44,430 --> 00:04:46,130 course for you and I would really appreciate it if you support my hard 246 00:04:46,130 --> 00:04:46,140 appreciate it if you support my hard 247 00:04:46,140 --> 00:04:48,230 appreciate it if you support my hard work by liking and sharing this video 248 00:04:48,230 --> 00:04:48,240 work by liking and sharing this video 249 00:04:48,240 --> 00:04:55,430 work by liking and sharing this video thank you so much now let's continue in 250 00:04:55,430 --> 00:04:55,440 thank you so much now let's continue in 251 00:04:55,440 --> 00:04:56,750 thank you so much now let's continue in this tutorial I'm going to show you how 252 00:04:56,750 --> 00:04:56,760 this tutorial I'm going to show you how 253 00:04:56,760 --> 00:04:59,630 this tutorial I'm going to show you how to install MySQL on your computer now 254 00:04:59,630 --> 00:04:59,640 to install MySQL on your computer now 255 00:04:59,640 --> 00:05:01,430 to install MySQL on your computer now here I'm using a Mac so first I will 256 00:05:01,430 --> 00:05:01,440 here I'm using a Mac so first I will 257 00:05:01,440 --> 00:05:03,830 here I'm using a Mac so first I will show you how to install MySQL on a Mac 258 00:05:03,830 --> 00:05:03,840 show you how to install MySQL on a Mac 259 00:05:03,840 --> 00:05:05,570 show you how to install MySQL on a Mac computer and then I will show you how to 260 00:05:05,570 --> 00:05:05,580 computer and then I will show you how to 261 00:05:05,580 --> 00:05:07,280 computer and then I will show you how to install it on windows so if you're a 262 00:05:07,280 --> 00:05:07,290 install it on windows so if you're a 263 00:05:07,290 --> 00:05:09,020 install it on windows so if you're a Windows user feel free to skip this 264 00:05:09,020 --> 00:05:09,030 Windows user feel free to skip this 265 00:05:09,030 --> 00:05:11,930 Windows user feel free to skip this tutorial now open up your browser and 266 00:05:11,930 --> 00:05:11,940 tutorial now open up your browser and 267 00:05:11,940 --> 00:05:15,980 tutorial now open up your browser and head over to MySQL calm then go to the 268 00:05:15,980 --> 00:05:15,990 head over to MySQL calm then go to the 269 00:05:15,990 --> 00:05:19,250 head over to MySQL calm then go to the downloads page and scroll down to the 270 00:05:19,250 --> 00:05:19,260 downloads page and scroll down to the 271 00:05:19,260 --> 00:05:21,740 downloads page and scroll down to the bottom here you should see my SQL 272 00:05:21,740 --> 00:05:21,750 bottom here you should see my SQL 273 00:05:21,750 --> 00:05:23,840 bottom here you should see my SQL community edition this is absolutely 274 00:05:23,840 --> 00:05:23,850 community edition this is absolutely 275 00:05:23,850 --> 00:05:25,250 community edition this is absolutely free and we gonna use that throughout 276 00:05:25,250 --> 00:05:25,260 free and we gonna use that throughout 277 00:05:25,260 --> 00:05:28,570 free and we gonna use that throughout this course so let's go ahead with that 278 00:05:28,570 --> 00:05:28,580 this course so let's go ahead with that 279 00:05:28,580 --> 00:05:31,090 this course so let's go ahead with that now on this page click on MySQL 280 00:05:31,090 --> 00:05:31,100 now on this page click on MySQL 281 00:05:31,100 --> 00:05:36,130 now on this page click on MySQL community server and then on this page 282 00:05:36,130 --> 00:05:36,140 community server and then on this page 283 00:05:36,140 --> 00:05:38,540 community server and then on this page you should see available releases for 284 00:05:38,540 --> 00:05:38,550 you should see available releases for 285 00:05:38,550 --> 00:05:41,300 you should see available releases for Mac OS so in this list download the 286 00:05:41,300 --> 00:05:41,310 Mac OS so in this list download the 287 00:05:41,310 --> 00:05:44,440 Mac OS so in this list download the first item which is a dmg archive 288 00:05:44,440 --> 00:05:44,450 first item which is a dmg archive 289 00:05:44,450 --> 00:05:48,560 first item which is a dmg archive alright now on the next page click on no 290 00:05:48,560 --> 00:05:48,570 alright now on the next page click on no 291 00:05:48,570 --> 00:05:51,710 alright now on the next page click on no thanks just start my download alright as 292 00:05:51,710 --> 00:05:51,720 thanks just start my download alright as 293 00:05:51,720 --> 00:05:53,840 thanks just start my download alright as you can see you are getting a dmg file 294 00:05:53,840 --> 00:05:53,850 you can see you are getting a dmg file 295 00:05:53,850 --> 00:05:56,270 you can see you are getting a dmg file which is basically a set of wizard all 296 00:05:56,270 --> 00:05:56,280 which is basically a set of wizard all 297 00:05:56,280 --> 00:05:58,970 which is basically a set of wizard all right now the dmg is downloaded so let's 298 00:05:58,970 --> 00:05:58,980 right now the dmg is downloaded so let's 299 00:05:58,980 --> 00:06:02,030 right now the dmg is downloaded so let's open it and then double click on this 300 00:06:02,030 --> 00:06:02,040 open it and then double click on this 301 00:06:02,040 --> 00:06:05,180 open it and then double click on this package this will launch an installation 302 00:06:05,180 --> 00:06:05,190 package this will launch an installation 303 00:06:05,190 --> 00:06:07,160 package this will launch an installation wizard which is pretty easy to use so 304 00:06:07,160 --> 00:06:07,170 wizard which is pretty easy to use so 305 00:06:07,170 --> 00:06:11,090 wizard which is pretty easy to use so simply click on continue and again and 306 00:06:11,090 --> 00:06:11,100 simply click on continue and again and 307 00:06:11,100 --> 00:06:13,850 simply click on continue and again and again I agree with the license agreement 308 00:06:13,850 --> 00:06:13,860 again I agree with the license agreement 309 00:06:13,860 --> 00:06:18,380 again I agree with the license agreement and install MySQL it's gonna ask for 310 00:06:18,380 --> 00:06:18,390 and install MySQL it's gonna ask for 311 00:06:18,390 --> 00:06:19,970 and install MySQL it's gonna ask for your password this is the password that 312 00:06:19,970 --> 00:06:19,980 your password this is the password that 313 00:06:19,980 --> 00:06:22,430 your password this is the password that you used to log in to your computer so 314 00:06:22,430 --> 00:06:22,440 you used to log in to your computer so 315 00:06:22,440 --> 00:06:26,390 you used to log in to your computer so let's put that here alright now here we 316 00:06:26,390 --> 00:06:26,400 let's put that here alright now here we 317 00:06:26,400 --> 00:06:28,250 let's put that here alright now here we need to set a password for the root or 318 00:06:28,250 --> 00:06:28,260 need to set a password for the root or 319 00:06:28,260 --> 00:06:32,659 need to set a password for the root or the admin user so click Next and in this 320 00:06:32,659 --> 00:06:32,669 the admin user so click Next and in this 321 00:06:32,669 --> 00:06:37,070 the admin user so click Next and in this box type a complex password 322 00:06:37,070 --> 00:06:37,080 323 00:06:37,080 --> 00:06:39,909 right now let's finish the installation 324 00:06:39,909 --> 00:06:39,919 right now let's finish the installation 325 00:06:39,919 --> 00:06:43,760 right now let's finish the installation and into your computer's password one 326 00:06:43,760 --> 00:06:43,770 and into your computer's password one 327 00:06:43,770 --> 00:06:49,040 and into your computer's password one more time and we're done that was super 328 00:06:49,040 --> 00:06:49,050 more time and we're done that was super 329 00:06:49,050 --> 00:06:53,270 more time and we're done that was super easy and sweet all right we installed 330 00:06:53,270 --> 00:06:53,280 easy and sweet all right we installed 331 00:06:53,280 --> 00:06:56,089 easy and sweet all right we installed MySQL community server now we need a 332 00:06:56,089 --> 00:06:56,099 MySQL community server now we need a 333 00:06:56,099 --> 00:06:58,040 MySQL community server now we need a graphical tool to connect to the server 334 00:06:58,040 --> 00:06:58,050 graphical tool to connect to the server 335 00:06:58,050 --> 00:07:01,670 graphical tool to connect to the server and manage our databases so back to the 336 00:07:01,670 --> 00:07:01,680 and manage our databases so back to the 337 00:07:01,680 --> 00:07:04,820 and manage our databases so back to the downloads page one more time scroll to 338 00:07:04,820 --> 00:07:04,830 downloads page one more time scroll to 339 00:07:04,830 --> 00:07:08,300 downloads page one more time scroll to the bottom and go to MySQL Community 340 00:07:08,300 --> 00:07:08,310 the bottom and go to MySQL Community 341 00:07:08,310 --> 00:07:12,050 the bottom and go to MySQL Community Edition and on this page somewhere you 342 00:07:12,050 --> 00:07:12,060 Edition and on this page somewhere you 343 00:07:12,060 --> 00:07:14,420 Edition and on this page somewhere you should see my SQL work bench this is a 344 00:07:14,420 --> 00:07:14,430 should see my SQL work bench this is a 345 00:07:14,430 --> 00:07:16,219 should see my SQL work bench this is a graphical tool that we used to connect 346 00:07:16,219 --> 00:07:16,229 graphical tool that we used to connect 347 00:07:16,229 --> 00:07:19,159 graphical tool that we used to connect to our database server so let's go ahead 348 00:07:19,159 --> 00:07:19,169 to our database server so let's go ahead 349 00:07:19,169 --> 00:07:23,629 to our database server so let's go ahead and download this as well now once again 350 00:07:23,629 --> 00:07:23,639 and download this as well now once again 351 00:07:23,639 --> 00:07:27,020 and download this as well now once again on this page we need to download a dmg 352 00:07:27,020 --> 00:07:27,030 on this page we need to download a dmg 353 00:07:27,030 --> 00:07:32,089 on this page we need to download a dmg archive so download and again we have to 354 00:07:32,089 --> 00:07:32,099 archive so download and again we have to 355 00:07:32,099 --> 00:07:33,680 archive so download and again we have to say no we don't want to log in or sign 356 00:07:33,680 --> 00:07:33,690 say no we don't want to log in or sign 357 00:07:33,690 --> 00:07:35,570 say no we don't want to log in or sign up so let's just go ahead and download 358 00:07:35,570 --> 00:07:35,580 up so let's just go ahead and download 359 00:07:35,580 --> 00:07:42,110 up so let's just go ahead and download the dmg and then open it all right 360 00:07:42,110 --> 00:07:42,120 the dmg and then open it all right 361 00:07:42,120 --> 00:07:43,399 the dmg and then open it all right you're gonna see something like this so 362 00:07:43,399 --> 00:07:43,409 you're gonna see something like this so 363 00:07:43,409 --> 00:07:46,100 you're gonna see something like this so simply drag this MySQL workbench and 364 00:07:46,100 --> 00:07:46,110 simply drag this MySQL workbench and 365 00:07:46,110 --> 00:07:48,709 simply drag this MySQL workbench and drop it onto the Applications folder so 366 00:07:48,709 --> 00:07:48,719 drop it onto the Applications folder so 367 00:07:48,719 --> 00:07:51,589 drop it onto the Applications folder so let's go ahead with that now it's going 368 00:07:51,589 --> 00:07:51,599 let's go ahead with that now it's going 369 00:07:51,599 --> 00:07:53,240 let's go ahead with that now it's going to copy this into the Applications 370 00:07:53,240 --> 00:07:53,250 to copy this into the Applications 371 00:07:53,250 --> 00:07:56,930 to copy this into the Applications folder beautiful so we're done with the 372 00:07:56,930 --> 00:07:56,940 folder beautiful so we're done with the 373 00:07:56,940 --> 00:07:59,659 folder beautiful so we're done with the installation that was super easy now 374 00:07:59,659 --> 00:07:59,669 installation that was super easy now 375 00:07:59,669 --> 00:08:02,740 installation that was super easy now press command on space and search for 376 00:08:02,740 --> 00:08:02,750 press command on space and search for 377 00:08:02,750 --> 00:08:06,740 press command on space and search for MySQL workbench there you go let's open 378 00:08:06,740 --> 00:08:06,750 MySQL workbench there you go let's open 379 00:08:06,750 --> 00:08:08,869 MySQL workbench there you go let's open it now the first time we get this 380 00:08:08,869 --> 00:08:08,879 it now the first time we get this 381 00:08:08,879 --> 00:08:10,700 it now the first time we get this message because this is our application 382 00:08:10,700 --> 00:08:10,710 message because this is our application 383 00:08:10,710 --> 00:08:11,839 message because this is our application that we have downloaded from the 384 00:08:11,839 --> 00:08:11,849 that we have downloaded from the 385 00:08:11,849 --> 00:08:14,059 that we have downloaded from the internet so we need to tell Mac that we 386 00:08:14,059 --> 00:08:14,069 internet so we need to tell Mac that we 387 00:08:14,069 --> 00:08:16,010 internet so we need to tell Mac that we trust this let's go ahead with that 388 00:08:16,010 --> 00:08:16,020 trust this let's go ahead with that 389 00:08:16,020 --> 00:08:19,670 trust this let's go ahead with that so this is MySQL workbench now by 390 00:08:19,670 --> 00:08:19,680 so this is MySQL workbench now by 391 00:08:19,680 --> 00:08:21,740 so this is MySQL workbench now by default you should see a connection here 392 00:08:21,740 --> 00:08:21,750 default you should see a connection here 393 00:08:21,750 --> 00:08:23,869 default you should see a connection here if you don't see that you need to create 394 00:08:23,869 --> 00:08:23,879 if you don't see that you need to create 395 00:08:23,879 --> 00:08:25,909 if you don't see that you need to create it let me show you how to do that so for 396 00:08:25,909 --> 00:08:25,919 it let me show you how to do that so for 397 00:08:25,919 --> 00:08:27,850 it let me show you how to do that so for this demo I'm gonna right-click this and 398 00:08:27,850 --> 00:08:27,860 this demo I'm gonna right-click this and 399 00:08:27,860 --> 00:08:32,360 this demo I'm gonna right-click this and delete this connection all right now 400 00:08:32,360 --> 00:08:32,370 delete this connection all right now 401 00:08:32,370 --> 00:08:33,740 delete this connection all right now let's create a connection from scratch 402 00:08:33,740 --> 00:08:33,750 let's create a connection from scratch 403 00:08:33,750 --> 00:08:37,880 let's create a connection from scratch so click on this plus icon on this page 404 00:08:37,880 --> 00:08:37,890 so click on this plus icon on this page 405 00:08:37,890 --> 00:08:40,100 so click on this plus icon on this page give this connection a name let's say 406 00:08:40,100 --> 00:08:40,110 give this connection a name let's say 407 00:08:40,110 --> 00:08:43,850 give this connection a name let's say local instance now the connection method 408 00:08:43,850 --> 00:08:43,860 local instance now the connection method 409 00:08:43,860 --> 00:08:46,250 local instance now the connection method that we're gonna use is tcp/ip which is 410 00:08:46,250 --> 00:08:46,260 that we're gonna use is tcp/ip which is 411 00:08:46,260 --> 00:08:49,269 that we're gonna use is tcp/ip which is set by default the host name is 412 00:08:49,269 --> 00:08:49,279 set by default the host name is 413 00:08:49,279 --> 00:08:50,930 set by default the host name is 127.0.0.1 414 00:08:50,930 --> 00:08:50,940 127.0.0.1 415 00:08:50,940 --> 00:08:53,000 127.0.0.1 point one which is the address of the 416 00:08:53,000 --> 00:08:53,010 point one which is the address of the 417 00:08:53,010 --> 00:08:55,430 point one which is the address of the local machine and the port is three 418 00:08:55,430 --> 00:08:55,440 local machine and the port is three 419 00:08:55,440 --> 00:08:57,740 local machine and the port is three three zero six this is the default port 420 00:08:57,740 --> 00:08:57,750 three zero six this is the default port 421 00:08:57,750 --> 00:09:00,350 three zero six this is the default port for my SQL Server that is the username 422 00:09:00,350 --> 00:09:00,360 for my SQL Server that is the username 423 00:09:00,360 --> 00:09:02,750 for my SQL Server that is the username of the admin now we need to enter the 424 00:09:02,750 --> 00:09:02,760 of the admin now we need to enter the 425 00:09:02,760 --> 00:09:04,880 of the admin now we need to enter the password this is the password that we 426 00:09:04,880 --> 00:09:04,890 password this is the password that we 427 00:09:04,890 --> 00:09:06,290 password this is the password that we set during the installation 428 00:09:06,290 --> 00:09:06,300 set during the installation 429 00:09:06,300 --> 00:09:10,250 set during the installation so click on store in keychain and in 430 00:09:10,250 --> 00:09:10,260 so click on store in keychain and in 431 00:09:10,260 --> 00:09:14,600 so click on store in keychain and in this box type the password for a MySQL 432 00:09:14,600 --> 00:09:14,610 this box type the password for a MySQL 433 00:09:14,610 --> 00:09:19,850 this box type the password for a MySQL server alright and finally let's test 434 00:09:19,850 --> 00:09:19,860 server alright and finally let's test 435 00:09:19,860 --> 00:09:22,700 server alright and finally let's test the connection okay we successfully 436 00:09:22,700 --> 00:09:22,710 the connection okay we successfully 437 00:09:22,710 --> 00:09:25,160 the connection okay we successfully connected to MySQL server on the local 438 00:09:25,160 --> 00:09:25,170 connected to MySQL server on the local 439 00:09:25,170 --> 00:09:28,300 connected to MySQL server on the local machine beautiful let's click OK and 440 00:09:28,300 --> 00:09:28,310 machine beautiful let's click OK and 441 00:09:28,310 --> 00:09:30,950 machine beautiful let's click OK and here we have a connection on the home 442 00:09:30,950 --> 00:09:30,960 here we have a connection on the home 443 00:09:30,960 --> 00:09:33,590 here we have a connection on the home page of MySQL workbench every time we 444 00:09:33,590 --> 00:09:33,600 page of MySQL workbench every time we 445 00:09:33,600 --> 00:09:35,810 page of MySQL workbench every time we open MySQL workbench we use this 446 00:09:35,810 --> 00:09:35,820 open MySQL workbench we use this 447 00:09:35,820 --> 00:09:37,190 open MySQL workbench we use this connection to connect to our local 448 00:09:37,190 --> 00:09:37,200 connection to connect to our local 449 00:09:37,200 --> 00:09:40,340 connection to connect to our local server alright we're done with the 450 00:09:40,340 --> 00:09:40,350 server alright we're done with the 451 00:09:40,350 --> 00:09:42,920 server alright we're done with the installation of MySQL on a Mac next I 452 00:09:42,920 --> 00:09:42,930 installation of MySQL on a Mac next I 453 00:09:42,930 --> 00:09:44,750 installation of MySQL on a Mac next I will talk about installing MySQL on a 454 00:09:44,750 --> 00:09:44,760 will talk about installing MySQL on a 455 00:09:44,760 --> 00:09:46,910 will talk about installing MySQL on a Windows computer so feel free to skip 456 00:09:46,910 --> 00:09:46,920 Windows computer so feel free to skip 457 00:09:46,920 --> 00:09:52,729 Windows computer so feel free to skip that tutorial 458 00:09:52,729 --> 00:09:52,739 459 00:09:52,739 --> 00:09:55,049 in this tutorial I'm gonna show you how 460 00:09:55,049 --> 00:09:55,059 in this tutorial I'm gonna show you how 461 00:09:55,059 --> 00:09:58,530 in this tutorial I'm gonna show you how to install MySQL on Windows so open up 462 00:09:58,530 --> 00:09:58,540 to install MySQL on Windows so open up 463 00:09:58,540 --> 00:10:01,129 to install MySQL on Windows so open up your browser and head over to MySQL comm 464 00:10:01,129 --> 00:10:01,139 your browser and head over to MySQL comm 465 00:10:01,139 --> 00:10:05,879 your browser and head over to MySQL comm then go to the downloads page now here 466 00:10:05,879 --> 00:10:05,889 then go to the downloads page now here 467 00:10:05,889 --> 00:10:09,239 then go to the downloads page now here scroll down to the bottom we're gonna 468 00:10:09,239 --> 00:10:09,249 scroll down to the bottom we're gonna 469 00:10:09,249 --> 00:10:11,519 scroll down to the bottom we're gonna use MySQL community edition which is 470 00:10:11,519 --> 00:10:11,529 use MySQL community edition which is 471 00:10:11,529 --> 00:10:14,929 use MySQL community edition which is absolutely free so let's go with this 472 00:10:14,929 --> 00:10:14,939 absolutely free so let's go with this 473 00:10:14,939 --> 00:10:19,879 absolutely free so let's go with this now select MySQL community server 474 00:10:19,879 --> 00:10:19,889 now select MySQL community server 475 00:10:19,889 --> 00:10:23,989 now select MySQL community server and then scroll down so here you should 476 00:10:23,989 --> 00:10:23,999 and then scroll down so here you should 477 00:10:23,999 --> 00:10:24,889 and then scroll down so here you should see something like this 478 00:10:24,889 --> 00:10:24,899 see something like this 479 00:10:24,899 --> 00:10:28,099 see something like this my SQL installer for Windows this is the 480 00:10:28,099 --> 00:10:28,109 my SQL installer for Windows this is the 481 00:10:28,109 --> 00:10:30,259 my SQL installer for Windows this is the recommended method for installing MySQL 482 00:10:30,259 --> 00:10:30,269 recommended method for installing MySQL 483 00:10:30,269 --> 00:10:34,400 recommended method for installing MySQL on Windows so click on this alright on 484 00:10:34,400 --> 00:10:34,410 on Windows so click on this alright on 485 00:10:34,410 --> 00:10:39,570 on Windows so click on this alright on the next page scroll down and 486 00:10:39,570 --> 00:10:39,580 487 00:10:39,580 --> 00:10:43,410 download the first installer here on the 488 00:10:43,410 --> 00:10:43,420 download the first installer here on the 489 00:10:43,420 --> 00:10:46,500 download the first installer here on the next page scroll down and click on no 490 00:10:46,500 --> 00:10:46,510 next page scroll down and click on no 491 00:10:46,510 --> 00:10:48,720 next page scroll down and click on no thanks just start my download otherwise 492 00:10:48,720 --> 00:10:48,730 thanks just start my download otherwise 493 00:10:48,730 --> 00:10:50,280 thanks just start my download otherwise you have to create an account and login 494 00:10:50,280 --> 00:10:50,290 you have to create an account and login 495 00:10:50,290 --> 00:10:52,320 you have to create an account and login which is unnecessary for following this 496 00:10:52,320 --> 00:10:52,330 which is unnecessary for following this 497 00:10:52,330 --> 00:10:56,790 which is unnecessary for following this course so let's go with this and save 498 00:10:56,790 --> 00:10:56,800 course so let's go with this and save 499 00:10:56,800 --> 00:11:05,230 course so let's go with this and save this file to a computer and then run it 500 00:11:05,230 --> 00:11:05,240 501 00:11:05,240 --> 00:11:06,460 all right we're gonna use this setup 502 00:11:06,460 --> 00:11:06,470 all right we're gonna use this setup 503 00:11:06,470 --> 00:11:08,949 all right we're gonna use this setup wizard to install MySQL on our computer 504 00:11:08,949 --> 00:11:08,959 wizard to install MySQL on our computer 505 00:11:08,959 --> 00:11:11,139 wizard to install MySQL on our computer this is very easy all you have to do is 506 00:11:11,139 --> 00:11:11,149 this is very easy all you have to do is 507 00:11:11,149 --> 00:11:13,239 this is very easy all you have to do is to click Next but there are a couple of 508 00:11:13,239 --> 00:11:13,249 to click Next but there are a couple of 509 00:11:13,249 --> 00:11:14,769 to click Next but there are a couple of places where you need to enter a 510 00:11:14,769 --> 00:11:14,779 places where you need to enter a 511 00:11:14,779 --> 00:11:17,470 places where you need to enter a password let me show you so on the first 512 00:11:17,470 --> 00:11:17,480 password let me show you so on the first 513 00:11:17,480 --> 00:11:19,299 password let me show you so on the first page for the setup type we're gonna use 514 00:11:19,299 --> 00:11:19,309 page for the setup type we're gonna use 515 00:11:19,309 --> 00:11:23,169 page for the setup type we're gonna use the developer default setup go to the 516 00:11:23,169 --> 00:11:23,179 the developer default setup go to the 517 00:11:23,179 --> 00:11:24,970 the developer default setup go to the next page now here we're getting a 518 00:11:24,970 --> 00:11:24,980 next page now here we're getting a 519 00:11:24,980 --> 00:11:26,679 next page now here we're getting a little warning because this installation 520 00:11:26,679 --> 00:11:26,689 little warning because this installation 521 00:11:26,689 --> 00:11:28,900 little warning because this installation wizard wants to install the connector 522 00:11:28,900 --> 00:11:28,910 wizard wants to install the connector 523 00:11:28,910 --> 00:11:32,739 wizard wants to install the connector for python 3.7 but I don't have python 524 00:11:32,739 --> 00:11:32,749 for python 3.7 but I don't have python 525 00:11:32,749 --> 00:11:34,389 for python 3.7 but I don't have python on this machine so that's why I'm 526 00:11:34,389 --> 00:11:34,399 on this machine so that's why I'm 527 00:11:34,399 --> 00:11:36,009 on this machine so that's why I'm getting this warning now on your machine 528 00:11:36,009 --> 00:11:36,019 getting this warning now on your machine 529 00:11:36,019 --> 00:11:37,689 getting this warning now on your machine you might or you might not get this 530 00:11:37,689 --> 00:11:37,699 you might or you might not get this 531 00:11:37,699 --> 00:11:39,040 you might or you might not get this error it doesn't really matter just 532 00:11:39,040 --> 00:11:39,050 error it doesn't really matter just 533 00:11:39,050 --> 00:11:44,109 error it doesn't really matter just click Next and one more time so here are 534 00:11:44,109 --> 00:11:44,119 click Next and one more time so here are 535 00:11:44,119 --> 00:11:46,059 click Next and one more time so here are the products are gonna get installed the 536 00:11:46,059 --> 00:11:46,069 the products are gonna get installed the 537 00:11:46,069 --> 00:11:49,210 the products are gonna get installed the first one is MySQL server the second one 538 00:11:49,210 --> 00:11:49,220 first one is MySQL server the second one 539 00:11:49,220 --> 00:11:51,939 first one is MySQL server the second one is MySQL workbench this is the graphical 540 00:11:51,939 --> 00:11:51,949 is MySQL workbench this is the graphical 541 00:11:51,949 --> 00:11:53,590 is MySQL workbench this is the graphical tool that we use to connect to our 542 00:11:53,590 --> 00:11:53,600 tool that we use to connect to our 543 00:11:53,600 --> 00:11:55,929 tool that we use to connect to our database server and manage our databases 544 00:11:55,929 --> 00:11:55,939 database server and manage our databases 545 00:11:55,939 --> 00:11:59,009 database server and manage our databases you're gonna see that soon so click on 546 00:11:59,009 --> 00:11:59,019 you're gonna see that soon so click on 547 00:11:59,019 --> 00:12:02,559 you're gonna see that soon so click on execute now this is gonna take about 548 00:12:02,559 --> 00:12:02,569 execute now this is gonna take about 549 00:12:02,569 --> 00:12:04,269 execute now this is gonna take about five to ten minutes so I'm going to 550 00:12:04,269 --> 00:12:04,279 five to ten minutes so I'm going to 551 00:12:04,279 --> 00:12:08,380 five to ten minutes so I'm going to pause the recording 552 00:12:08,380 --> 00:12:08,390 553 00:12:08,390 --> 00:12:10,000 all right all the products are installed 554 00:12:10,000 --> 00:12:10,010 all right all the products are installed 555 00:12:10,010 --> 00:12:12,540 all right all the products are installed beautiful let's go to the next page and 556 00:12:12,540 --> 00:12:12,550 beautiful let's go to the next page and 557 00:12:12,550 --> 00:12:16,269 beautiful let's go to the next page and again here on the group replication page 558 00:12:16,269 --> 00:12:16,279 again here on the group replication page 559 00:12:16,279 --> 00:12:19,720 again here on the group replication page also click on next and the next page 560 00:12:19,720 --> 00:12:19,730 also click on next and the next page 561 00:12:19,730 --> 00:12:21,880 also click on next and the next page which is about networking leave all the 562 00:12:21,880 --> 00:12:21,890 which is about networking leave all the 563 00:12:21,890 --> 00:12:24,610 which is about networking leave all the default settings so let's go to the next 564 00:12:24,610 --> 00:12:24,620 default settings so let's go to the next 565 00:12:24,620 --> 00:12:27,430 default settings so let's go to the next page now we should set a password for 566 00:12:27,430 --> 00:12:27,440 page now we should set a password for 567 00:12:27,440 --> 00:12:30,400 page now we should set a password for the root or the admin user so click on 568 00:12:30,400 --> 00:12:30,410 the root or the admin user so click on 569 00:12:30,410 --> 00:12:34,569 the root or the admin user so click on next and in this box type a password for 570 00:12:34,569 --> 00:12:34,579 next and in this box type a password for 571 00:12:34,579 --> 00:12:40,660 next and in this box type a password for the admin user alright and then let's go 572 00:12:40,660 --> 00:12:40,670 the admin user alright and then let's go 573 00:12:40,670 --> 00:12:43,000 the admin user alright and then let's go to the next page once again leave all 574 00:12:43,000 --> 00:12:43,010 to the next page once again leave all 575 00:12:43,010 --> 00:12:45,730 to the next page once again leave all the default settings and click on next 576 00:12:45,730 --> 00:12:45,740 the default settings and click on next 577 00:12:45,740 --> 00:12:50,610 the default settings and click on next and execute one more time 578 00:12:50,610 --> 00:12:50,620 579 00:12:50,620 --> 00:12:53,040 all right and now let's finish the 580 00:12:53,040 --> 00:12:53,050 all right and now let's finish the 581 00:12:53,050 --> 00:12:55,500 all right and now let's finish the installation once again we have to click 582 00:12:55,500 --> 00:12:55,510 installation once again we have to click 583 00:12:55,510 --> 00:13:00,000 installation once again we have to click on next and then finish one more time 584 00:13:00,000 --> 00:13:00,010 on next and then finish one more time 585 00:13:00,010 --> 00:13:02,280 on next and then finish one more time there are so many steps now here's the 586 00:13:02,280 --> 00:13:02,290 there are so many steps now here's the 587 00:13:02,290 --> 00:13:04,320 there are so many steps now here's the page where you need to enter the admin 588 00:13:04,320 --> 00:13:04,330 page where you need to enter the admin 589 00:13:04,330 --> 00:13:06,660 page where you need to enter the admin password so the page is called connect 590 00:13:06,660 --> 00:13:06,670 password so the page is called connect 591 00:13:06,670 --> 00:13:08,850 password so the page is called connect to server you can see the user name is 592 00:13:08,850 --> 00:13:08,860 to server you can see the user name is 593 00:13:08,860 --> 00:13:11,820 to server you can see the user name is root which represents the admin user so 594 00:13:11,820 --> 00:13:11,830 root which represents the admin user so 595 00:13:11,830 --> 00:13:15,330 root which represents the admin user so in this box enter the password that you 596 00:13:15,330 --> 00:13:15,340 in this box enter the password that you 597 00:13:15,340 --> 00:13:18,990 in this box enter the password that you said earlier then click on check ok 598 00:13:18,990 --> 00:13:19,000 said earlier then click on check ok 599 00:13:19,000 --> 00:13:20,630 said earlier then click on check ok connection was successful beautiful 600 00:13:20,630 --> 00:13:20,640 connection was successful beautiful 601 00:13:20,640 --> 00:13:24,810 connection was successful beautiful let's go to the next page and click on 602 00:13:24,810 --> 00:13:24,820 let's go to the next page and click on 603 00:13:24,820 --> 00:13:29,070 let's go to the next page and click on execute and finally finish there you go 604 00:13:29,070 --> 00:13:29,080 execute and finally finish there you go 605 00:13:29,080 --> 00:13:32,280 execute and finally finish there you go we have one more step next now finally 606 00:13:32,280 --> 00:13:32,290 we have one more step next now finally 607 00:13:32,290 --> 00:13:35,040 we have one more step next now finally after all these steps the installation 608 00:13:35,040 --> 00:13:35,050 after all these steps the installation 609 00:13:35,050 --> 00:13:37,140 after all these steps the installation is complete now this is gonna start 610 00:13:37,140 --> 00:13:37,150 is complete now this is gonna start 611 00:13:37,150 --> 00:13:40,020 is complete now this is gonna start MySQL workbench which is the graphical 612 00:13:40,020 --> 00:13:40,030 MySQL workbench which is the graphical 613 00:13:40,030 --> 00:13:41,790 MySQL workbench which is the graphical tool we used to manage our databases and 614 00:13:41,790 --> 00:13:41,800 tool we used to manage our databases and 615 00:13:41,800 --> 00:13:46,860 tool we used to manage our databases and run sequel queries so click on finish so 616 00:13:46,860 --> 00:13:46,870 run sequel queries so click on finish so 617 00:13:46,870 --> 00:13:48,180 run sequel queries so click on finish so now we have a command prompt window 618 00:13:48,180 --> 00:13:48,190 now we have a command prompt window 619 00:13:48,190 --> 00:13:50,880 now we have a command prompt window where we can type instructions to talk 620 00:13:50,880 --> 00:13:50,890 where we can type instructions to talk 621 00:13:50,890 --> 00:13:52,950 where we can type instructions to talk to our MySQL server we don't really need 622 00:13:52,950 --> 00:13:52,960 to our MySQL server we don't really need 623 00:13:52,960 --> 00:13:57,090 to our MySQL server we don't really need this so close it and here's MySQL 624 00:13:57,090 --> 00:13:57,100 this so close it and here's MySQL 625 00:13:57,100 --> 00:13:59,580 this so close it and here's MySQL workbench now the first time you open 626 00:13:59,580 --> 00:13:59,590 workbench now the first time you open 627 00:13:59,590 --> 00:14:01,320 workbench now the first time you open this page by default you should see a 628 00:14:01,320 --> 00:14:01,330 this page by default you should see a 629 00:14:01,330 --> 00:14:03,210 this page by default you should see a connection here if you don't see it 630 00:14:03,210 --> 00:14:03,220 connection here if you don't see it 631 00:14:03,220 --> 00:14:08,490 connection here if you don't see it click on this plus icon on this page 632 00:14:08,490 --> 00:14:08,500 click on this plus icon on this page 633 00:14:08,500 --> 00:14:10,890 click on this plus icon on this page give this connection and name let's say 634 00:14:10,890 --> 00:14:10,900 give this connection and name let's say 635 00:14:10,900 --> 00:14:14,160 give this connection and name let's say local instance now leave all the 636 00:14:14,160 --> 00:14:14,170 local instance now leave all the 637 00:14:14,170 --> 00:14:16,470 local instance now leave all the settings to their default value but here 638 00:14:16,470 --> 00:14:16,480 settings to their default value but here 639 00:14:16,480 --> 00:14:19,350 settings to their default value but here for the password click on store involved 640 00:14:19,350 --> 00:14:19,360 for the password click on store involved 641 00:14:19,360 --> 00:14:22,680 for the password click on store involved and in this box type the password that 642 00:14:22,680 --> 00:14:22,690 and in this box type the password that 643 00:14:22,690 --> 00:14:25,500 and in this box type the password that you set for the admin user so I'm gonna 644 00:14:25,500 --> 00:14:25,510 you set for the admin user so I'm gonna 645 00:14:25,510 --> 00:14:26,360 you set for the admin user so I'm gonna put that here 646 00:14:26,360 --> 00:14:26,370 put that here 647 00:14:26,370 --> 00:14:33,480 put that here ok now click on test connection alright 648 00:14:33,480 --> 00:14:33,490 ok now click on test connection alright 649 00:14:33,490 --> 00:14:35,430 ok now click on test connection alright it's successfully connected to the MySQL 650 00:14:35,430 --> 00:14:35,440 it's successfully connected to the MySQL 651 00:14:35,440 --> 00:14:36,660 it's successfully connected to the MySQL server on this computer 652 00:14:36,660 --> 00:14:36,670 server on this computer 653 00:14:36,670 --> 00:14:41,460 server on this computer alright then click on OK now we click on 654 00:14:41,460 --> 00:14:41,470 alright then click on OK now we click on 655 00:14:41,470 --> 00:14:42,720 alright then click on OK now we click on this connection to connect to our 656 00:14:42,720 --> 00:14:42,730 this connection to connect to our 657 00:14:42,730 --> 00:14:45,360 this connection to connect to our database server alright so here is the 658 00:14:45,360 --> 00:14:45,370 database server alright so here is the 659 00:14:45,370 --> 00:14:46,560 database server alright so here is the interface that you'll be using 660 00:14:46,560 --> 00:14:46,570 interface that you'll be using 661 00:14:46,570 --> 00:14:48,630 interface that you'll be using throughout this course on the left side 662 00:14:48,630 --> 00:14:48,640 throughout this course on the left side 663 00:14:48,640 --> 00:14:50,880 throughout this course on the left side we have the Navigator panel in the 664 00:14:50,880 --> 00:14:50,890 we have the Navigator panel in the 665 00:14:50,890 --> 00:14:53,550 we have the Navigator panel in the middle we have the query editor which we 666 00:14:53,550 --> 00:14:53,560 middle we have the query editor which we 667 00:14:53,560 --> 00:14:56,610 middle we have the query editor which we can resize this is where we're gonna 668 00:14:56,610 --> 00:14:56,620 can resize this is where we're gonna 669 00:14:56,620 --> 00:14:59,160 can resize this is where we're gonna write our sequel queries and on the 670 00:14:59,160 --> 00:14:59,170 write our sequel queries and on the 671 00:14:59,170 --> 00:15:02,010 write our sequel queries and on the right side we have sequel editions so 672 00:15:02,010 --> 00:15:02,020 right side we have sequel editions so 673 00:15:02,020 --> 00:15:03,210 right side we have sequel editions so we're done with the installation of 674 00:15:03,210 --> 00:15:03,220 we're done with the installation of 675 00:15:03,220 --> 00:15:04,820 we're done with the installation of MySQL on our 676 00:15:04,820 --> 00:15:04,830 MySQL on our 677 00:15:04,830 --> 00:15:06,620 MySQL on our next I'm gonna show you how to create 678 00:15:06,620 --> 00:15:06,630 next I'm gonna show you how to create 679 00:15:06,630 --> 00:15:14,360 next I'm gonna show you how to create the databases for this course in this 680 00:15:14,360 --> 00:15:14,370 the databases for this course in this 681 00:15:14,370 --> 00:15:15,770 the databases for this course in this tutorial I'm gonna show you how to 682 00:15:15,770 --> 00:15:15,780 tutorial I'm gonna show you how to 683 00:15:15,780 --> 00:15:18,500 tutorial I'm gonna show you how to create the databases for this course so 684 00:15:18,500 --> 00:15:18,510 create the databases for this course so 685 00:15:18,510 --> 00:15:21,470 create the databases for this course so here I've got my SQL work bench open let 686 00:15:21,470 --> 00:15:21,480 here I've got my SQL work bench open let 687 00:15:21,480 --> 00:15:23,150 here I've got my SQL work bench open let me quickly give you an overview of this 688 00:15:23,150 --> 00:15:23,160 me quickly give you an overview of this 689 00:15:23,160 --> 00:15:25,070 me quickly give you an overview of this interface because the first time you 690 00:15:25,070 --> 00:15:25,080 interface because the first time you 691 00:15:25,080 --> 00:15:27,110 interface because the first time you open it it might appear a little bit 692 00:15:27,110 --> 00:15:27,120 open it it might appear a little bit 693 00:15:27,120 --> 00:15:28,880 open it it might appear a little bit intimidating but actually it's not that 694 00:15:28,880 --> 00:15:28,890 intimidating but actually it's not that 695 00:15:28,890 --> 00:15:31,400 intimidating but actually it's not that difficult so here on the top we've got 696 00:15:31,400 --> 00:15:31,410 difficult so here on the top we've got 697 00:15:31,410 --> 00:15:33,380 difficult so here on the top we've got this toolbar with these buttons for 698 00:15:33,380 --> 00:15:33,390 this toolbar with these buttons for 699 00:15:33,390 --> 00:15:35,750 this toolbar with these buttons for creating a new tab for writing stick 700 00:15:35,750 --> 00:15:35,760 creating a new tab for writing stick 701 00:15:35,760 --> 00:15:38,360 creating a new tab for writing stick well code as well as opening a sequel 702 00:15:38,360 --> 00:15:38,370 well code as well as opening a sequel 703 00:15:38,370 --> 00:15:40,640 well code as well as opening a sequel file and next to that we've got a bunch 704 00:15:40,640 --> 00:15:40,650 file and next to that we've got a bunch 705 00:15:40,650 --> 00:15:42,290 file and next to that we've got a bunch of buttons for creating a database 706 00:15:42,290 --> 00:15:42,300 of buttons for creating a database 707 00:15:42,300 --> 00:15:45,020 of buttons for creating a database creating new tables and so on on the 708 00:15:45,020 --> 00:15:45,030 creating new tables and so on on the 709 00:15:45,030 --> 00:15:46,970 creating new tables and so on on the left side we've got the Navigator panel 710 00:15:46,970 --> 00:15:46,980 left side we've got the Navigator panel 711 00:15:46,980 --> 00:15:50,300 left side we've got the Navigator panel with two tabs administration and schemas 712 00:15:50,300 --> 00:15:50,310 with two tabs administration and schemas 713 00:15:50,310 --> 00:15:52,430 with two tabs administration and schemas we use the administration tab to do 714 00:15:52,430 --> 00:15:52,440 we use the administration tab to do 715 00:15:52,440 --> 00:15:54,950 we use the administration tab to do administrative work such as starting or 716 00:15:54,950 --> 00:15:54,960 administrative work such as starting or 717 00:15:54,960 --> 00:15:57,260 administrative work such as starting or stopping our server importing or 718 00:15:57,260 --> 00:15:57,270 stopping our server importing or 719 00:15:57,270 --> 00:15:59,960 stopping our server importing or exporting data and so on this schemas 720 00:15:59,960 --> 00:15:59,970 exporting data and so on this schemas 721 00:15:59,970 --> 00:16:02,390 exporting data and so on this schemas tab shows that databases that we have in 722 00:16:02,390 --> 00:16:02,400 tab shows that databases that we have in 723 00:16:02,400 --> 00:16:04,910 tab shows that databases that we have in the current database server so currently 724 00:16:04,910 --> 00:16:04,920 the current database server so currently 725 00:16:04,920 --> 00:16:07,250 the current database server so currently we only have one database that is sis 726 00:16:07,250 --> 00:16:07,260 we only have one database that is sis 727 00:16:07,260 --> 00:16:09,920 we only have one database that is sis and this is the database that MySQL uses 728 00:16:09,920 --> 00:16:09,930 and this is the database that MySQL uses 729 00:16:09,930 --> 00:16:13,040 and this is the database that MySQL uses internally to do its work now in the 730 00:16:13,040 --> 00:16:13,050 internally to do its work now in the 731 00:16:13,050 --> 00:16:14,480 internally to do its work now in the middle we've got this query editor 732 00:16:14,480 --> 00:16:14,490 middle we've got this query editor 733 00:16:14,490 --> 00:16:16,460 middle we've got this query editor window this is where we write our sequel 734 00:16:16,460 --> 00:16:16,470 window this is where we write our sequel 735 00:16:16,470 --> 00:16:18,320 window this is where we write our sequel code so we'll be spending most of our 736 00:16:18,320 --> 00:16:18,330 code so we'll be spending most of our 737 00:16:18,330 --> 00:16:20,720 code so we'll be spending most of our time in this course in this window and 738 00:16:20,720 --> 00:16:20,730 time in this course in this window and 739 00:16:20,730 --> 00:16:22,670 time in this course in this window and on the right side we've got another 740 00:16:22,670 --> 00:16:22,680 on the right side we've got another 741 00:16:22,680 --> 00:16:25,160 on the right side we've got another panel with two tabs context help and 742 00:16:25,160 --> 00:16:25,170 panel with two tabs context help and 743 00:16:25,170 --> 00:16:27,380 panel with two tabs context help and snippets the chances are at this 744 00:16:27,380 --> 00:16:27,390 snippets the chances are at this 745 00:16:27,390 --> 00:16:29,030 snippets the chances are at this interface might look slightly different 746 00:16:29,030 --> 00:16:29,040 interface might look slightly different 747 00:16:29,040 --> 00:16:31,340 interface might look slightly different on Windows but what I'm showing you here 748 00:16:31,340 --> 00:16:31,350 on Windows but what I'm showing you here 749 00:16:31,350 --> 00:16:33,980 on Windows but what I'm showing you here is almost identical with what we have on 750 00:16:33,980 --> 00:16:33,990 is almost identical with what we have on 751 00:16:33,990 --> 00:16:36,200 is almost identical with what we have on Windows so don't get hung up if it looks 752 00:16:36,200 --> 00:16:36,210 Windows so don't get hung up if it looks 753 00:16:36,210 --> 00:16:37,670 Windows so don't get hung up if it looks slightly different on your machine it 754 00:16:37,670 --> 00:16:37,680 slightly different on your machine it 755 00:16:37,680 --> 00:16:40,340 slightly different on your machine it doesn't really matter now up here we've 756 00:16:40,340 --> 00:16:40,350 doesn't really matter now up here we've 757 00:16:40,350 --> 00:16:42,500 doesn't really matter now up here we've got these buttons for showing or hiding 758 00:16:42,500 --> 00:16:42,510 got these buttons for showing or hiding 759 00:16:42,510 --> 00:16:44,900 got these buttons for showing or hiding these panels so to clean this interface 760 00:16:44,900 --> 00:16:44,910 these panels so to clean this interface 761 00:16:44,910 --> 00:16:47,150 these panels so to clean this interface I'm gonna hide this panel on the right 762 00:16:47,150 --> 00:16:47,160 I'm gonna hide this panel on the right 763 00:16:47,160 --> 00:16:49,579 I'm gonna hide this panel on the right side as well as the panel on the bottom 764 00:16:49,579 --> 00:16:49,589 side as well as the panel on the bottom 765 00:16:49,589 --> 00:16:52,490 side as well as the panel on the bottom that is better now to create the 766 00:16:52,490 --> 00:16:52,500 that is better now to create the 767 00:16:52,500 --> 00:16:54,770 that is better now to create the databases for this course download the 768 00:16:54,770 --> 00:16:54,780 databases for this course download the 769 00:16:54,780 --> 00:16:57,190 databases for this course download the zip file I've attached below this video 770 00:16:57,190 --> 00:16:57,200 zip file I've attached below this video 771 00:16:57,200 --> 00:16:59,390 zip file I've attached below this video when you extract the zip file you're 772 00:16:59,390 --> 00:16:59,400 when you extract the zip file you're 773 00:16:59,400 --> 00:17:01,070 when you extract the zip file you're gonna see a bunch of sequel files like 774 00:17:01,070 --> 00:17:01,080 gonna see a bunch of sequel files like 775 00:17:01,080 --> 00:17:03,110 gonna see a bunch of sequel files like this so the main one that you will be 776 00:17:03,110 --> 00:17:03,120 this so the main one that you will be 777 00:17:03,120 --> 00:17:05,150 this so the main one that you will be using in this tutorial is called create 778 00:17:05,150 --> 00:17:05,160 using in this tutorial is called create 779 00:17:05,160 --> 00:17:08,300 using in this tutorial is called create databases dot sequel so this file 780 00:17:08,300 --> 00:17:08,310 databases dot sequel so this file 781 00:17:08,310 --> 00:17:10,280 databases dot sequel so this file contains all the sequel code to create 782 00:17:10,280 --> 00:17:10,290 contains all the sequel code to create 783 00:17:10,290 --> 00:17:12,199 contains all the sequel code to create all the databases that we need in this 784 00:17:12,199 --> 00:17:12,209 all the databases that we need in this 785 00:17:12,209 --> 00:17:14,720 all the databases that we need in this course now we also have individual files 786 00:17:14,720 --> 00:17:14,730 course now we also have individual files 787 00:17:14,730 --> 00:17:17,689 course now we also have individual files for creating individual databases I just 788 00:17:17,689 --> 00:17:17,699 for creating individual databases I just 789 00:17:17,699 --> 00:17:18,130 for creating individual databases I just added 790 00:17:18,130 --> 00:17:18,140 added 791 00:17:18,140 --> 00:17:20,199 added files in case you need to recreate one 792 00:17:20,199 --> 00:17:20,209 files in case you need to recreate one 793 00:17:20,209 --> 00:17:21,910 files in case you need to recreate one of these databases in the future but for 794 00:17:21,910 --> 00:17:21,920 of these databases in the future but for 795 00:17:21,920 --> 00:17:24,610 of these databases in the future but for now don't worry about them now back to 796 00:17:24,610 --> 00:17:24,620 now don't worry about them now back to 797 00:17:24,620 --> 00:17:28,630 now don't worry about them now back to MySQL workbench let's open the main 798 00:17:28,630 --> 00:17:28,640 MySQL workbench let's open the main 799 00:17:28,640 --> 00:17:34,060 MySQL workbench let's open the main sequel file that is create databases so 800 00:17:34,060 --> 00:17:34,070 sequel file that is create databases so 801 00:17:34,070 --> 00:17:36,340 sequel file that is create databases so this is an example of sequel code that 802 00:17:36,340 --> 00:17:36,350 this is an example of sequel code that 803 00:17:36,350 --> 00:17:38,110 this is an example of sequel code that this may look complex at the beginning 804 00:17:38,110 --> 00:17:38,120 this may look complex at the beginning 805 00:17:38,120 --> 00:17:39,910 this may look complex at the beginning but trust me as you go through the 806 00:17:39,910 --> 00:17:39,920 but trust me as you go through the 807 00:17:39,920 --> 00:17:41,140 but trust me as you go through the course you're gonna understand exactly 808 00:17:41,140 --> 00:17:41,150 course you're gonna understand exactly 809 00:17:41,150 --> 00:17:43,660 course you're gonna understand exactly how everything works here you're gonna 810 00:17:43,660 --> 00:17:43,670 how everything works here you're gonna 811 00:17:43,670 --> 00:17:45,630 how everything works here you're gonna be able to write sequel code like this 812 00:17:45,630 --> 00:17:45,640 be able to write sequel code like this 813 00:17:45,640 --> 00:17:49,030 be able to write sequel code like this so we want to execute this to create all 814 00:17:49,030 --> 00:17:49,040 so we want to execute this to create all 815 00:17:49,040 --> 00:17:51,550 so we want to execute this to create all the databases for this course to do that 816 00:17:51,550 --> 00:17:51,560 the databases for this course to do that 817 00:17:51,560 --> 00:17:53,920 the databases for this course to do that we click on this icon this yellow 818 00:17:53,920 --> 00:17:53,930 we click on this icon this yellow 819 00:17:53,930 --> 00:17:56,470 we click on this icon this yellow Thunder icon that we have on this 820 00:17:56,470 --> 00:17:56,480 Thunder icon that we have on this 821 00:17:56,480 --> 00:17:58,570 Thunder icon that we have on this toolbar here this will execute either 822 00:17:58,570 --> 00:17:58,580 toolbar here this will execute either 823 00:17:58,580 --> 00:18:00,940 toolbar here this will execute either the selection or the entire code if 824 00:18:00,940 --> 00:18:00,950 the selection or the entire code if 825 00:18:00,950 --> 00:18:03,130 the selection or the entire code if there is nothing selected for example if 826 00:18:03,130 --> 00:18:03,140 there is nothing selected for example if 827 00:18:03,140 --> 00:18:04,870 there is nothing selected for example if I select this line here and click on 828 00:18:04,870 --> 00:18:04,880 I select this line here and click on 829 00:18:04,880 --> 00:18:06,910 I select this line here and click on this icon this will execute only this 830 00:18:06,910 --> 00:18:06,920 this icon this will execute only this 831 00:18:06,920 --> 00:18:08,800 this icon this will execute only this line in this case we want to execute the 832 00:18:08,800 --> 00:18:08,810 line in this case we want to execute the 833 00:18:08,810 --> 00:18:10,630 line in this case we want to execute the entire code so we shouldn't select 834 00:18:10,630 --> 00:18:10,640 entire code so we shouldn't select 835 00:18:10,640 --> 00:18:13,380 entire code so we shouldn't select anything and now let's execute this 836 00:18:13,380 --> 00:18:13,390 anything and now let's execute this 837 00:18:13,390 --> 00:18:16,210 anything and now let's execute this beautiful so here down the bottom we 838 00:18:16,210 --> 00:18:16,220 beautiful so here down the bottom we 839 00:18:16,220 --> 00:18:18,250 beautiful so here down the bottom we have this panel called the output window 840 00:18:18,250 --> 00:18:18,260 have this panel called the output window 841 00:18:18,260 --> 00:18:20,740 have this panel called the output window that shows all the operations performed 842 00:18:20,740 --> 00:18:20,750 that shows all the operations performed 843 00:18:20,750 --> 00:18:23,500 that shows all the operations performed in our database server so we can check 844 00:18:23,500 --> 00:18:23,510 in our database server so we can check 845 00:18:23,510 --> 00:18:25,540 in our database server so we can check to see if all the operations completed 846 00:18:25,540 --> 00:18:25,550 to see if all the operations completed 847 00:18:25,550 --> 00:18:27,910 to see if all the operations completed successfully or something went wrong as 848 00:18:27,910 --> 00:18:27,920 successfully or something went wrong as 849 00:18:27,920 --> 00:18:30,070 successfully or something went wrong as you can see we've got is green ticks 850 00:18:30,070 --> 00:18:30,080 you can see we've got is green ticks 851 00:18:30,080 --> 00:18:33,040 you can see we've got is green ticks next to each operation beautiful so I'm 852 00:18:33,040 --> 00:18:33,050 next to each operation beautiful so I'm 853 00:18:33,050 --> 00:18:35,800 next to each operation beautiful so I'm going to close this panel that's better 854 00:18:35,800 --> 00:18:35,810 going to close this panel that's better 855 00:18:35,810 --> 00:18:38,530 going to close this panel that's better now on the left side in the schemas tab 856 00:18:38,530 --> 00:18:38,540 now on the left side in the schemas tab 857 00:18:38,540 --> 00:18:40,300 now on the left side in the schemas tab currently we don't see the new databases 858 00:18:40,300 --> 00:18:40,310 currently we don't see the new databases 859 00:18:40,310 --> 00:18:42,730 currently we don't see the new databases so we'll have to refresh this view 860 00:18:42,730 --> 00:18:42,740 so we'll have to refresh this view 861 00:18:42,740 --> 00:18:45,340 so we'll have to refresh this view beautiful so we've got all these 862 00:18:45,340 --> 00:18:45,350 beautiful so we've got all these 863 00:18:45,350 --> 00:18:48,310 beautiful so we've got all these databases that are prefixed with SQL or 864 00:18:48,310 --> 00:18:48,320 databases that are prefixed with SQL or 865 00:18:48,320 --> 00:18:50,680 databases that are prefixed with SQL or sequel I decided to prefix them with 866 00:18:50,680 --> 00:18:50,690 sequel I decided to prefix them with 867 00:18:50,690 --> 00:18:52,450 sequel I decided to prefix them with sequel so we know that these are the 868 00:18:52,450 --> 00:18:52,460 sequel so we know that these are the 869 00:18:52,460 --> 00:18:54,400 sequel so we know that these are the databases for this course they don't 870 00:18:54,400 --> 00:18:54,410 databases for this course they don't 871 00:18:54,410 --> 00:18:56,470 databases for this course they don't accidentally clash with another database 872 00:18:56,470 --> 00:18:56,480 accidentally clash with another database 873 00:18:56,480 --> 00:18:58,540 accidentally clash with another database with the same name on your database 874 00:18:58,540 --> 00:18:58,550 with the same name on your database 875 00:18:58,550 --> 00:19:00,790 with the same name on your database server now at the time of recording this 876 00:19:00,790 --> 00:19:00,800 server now at the time of recording this 877 00:19:00,800 --> 00:19:03,010 server now at the time of recording this video there are only four databases here 878 00:19:03,010 --> 00:19:03,020 video there are only four databases here 879 00:19:03,020 --> 00:19:04,870 video there are only four databases here but as we go through the course I'm 880 00:19:04,870 --> 00:19:04,880 but as we go through the course I'm 881 00:19:04,880 --> 00:19:06,790 but as we go through the course I'm gonna update the script for creating the 882 00:19:06,790 --> 00:19:06,800 gonna update the script for creating the 883 00:19:06,800 --> 00:19:09,310 gonna update the script for creating the databases so when you watch this course 884 00:19:09,310 --> 00:19:09,320 databases so when you watch this course 885 00:19:09,320 --> 00:19:10,600 databases so when you watch this course chances are you're gonna see more 886 00:19:10,600 --> 00:19:10,610 chances are you're gonna see more 887 00:19:10,610 --> 00:19:12,340 chances are you're gonna see more databases here don't worry about a 888 00:19:12,340 --> 00:19:12,350 databases here don't worry about a 889 00:19:12,350 --> 00:19:14,980 databases here don't worry about a difference now as an example let's 890 00:19:14,980 --> 00:19:14,990 difference now as an example let's 891 00:19:14,990 --> 00:19:17,710 difference now as an example let's explore one of this databases and by the 892 00:19:17,710 --> 00:19:17,720 explore one of this databases and by the 893 00:19:17,720 --> 00:19:19,420 explore one of this databases and by the way we don't need this tab anymore so 894 00:19:19,420 --> 00:19:19,430 way we don't need this tab anymore so 895 00:19:19,430 --> 00:19:21,040 way we don't need this tab anymore so let's close it that's better 896 00:19:21,040 --> 00:19:21,050 let's close it that's better 897 00:19:21,050 --> 00:19:24,540 let's close it that's better let's expand the sequel store database 898 00:19:24,540 --> 00:19:24,550 let's expand the sequel store database 899 00:19:24,550 --> 00:19:26,860 let's expand the sequel store database now in every database we have these 900 00:19:26,860 --> 00:19:26,870 now in every database we have these 901 00:19:26,870 --> 00:19:29,470 now in every database we have these objects we have tables this is where we 902 00:19:29,470 --> 00:19:29,480 objects we have tables this is where we 903 00:19:29,480 --> 00:19:31,500 objects we have tables this is where we store our data we 904 00:19:31,500 --> 00:19:31,510 store our data we 905 00:19:31,510 --> 00:19:33,420 store our data we views which are kind of like virtual 906 00:19:33,420 --> 00:19:33,430 views which are kind of like virtual 907 00:19:33,430 --> 00:19:35,670 views which are kind of like virtual tables so we can combine data from 908 00:19:35,670 --> 00:19:35,680 tables so we can combine data from 909 00:19:35,680 --> 00:19:38,220 tables so we can combine data from multiple tables and put them in a view 910 00:19:38,220 --> 00:19:38,230 multiple tables and put them in a view 911 00:19:38,230 --> 00:19:40,020 multiple tables and put them in a view and this is especially powerful for 912 00:19:40,020 --> 00:19:40,030 and this is especially powerful for 913 00:19:40,030 --> 00:19:41,640 and this is especially powerful for creating reports you're going to learn 914 00:19:41,640 --> 00:19:41,650 creating reports you're going to learn 915 00:19:41,650 --> 00:19:43,860 creating reports you're going to learn about them in the future we also have 916 00:19:43,860 --> 00:19:43,870 about them in the future we also have 917 00:19:43,870 --> 00:19:46,350 about them in the future we also have stored procedures and functions and 918 00:19:46,350 --> 00:19:46,360 stored procedures and functions and 919 00:19:46,360 --> 00:19:48,330 stored procedures and functions and these are little programs that we store 920 00:19:48,330 --> 00:19:48,340 these are little programs that we store 921 00:19:48,340 --> 00:19:50,520 these are little programs that we store inside of our database for querying data 922 00:19:50,520 --> 00:19:50,530 inside of our database for querying data 923 00:19:50,530 --> 00:19:52,620 inside of our database for querying data for example we can have a stored 924 00:19:52,620 --> 00:19:52,630 for example we can have a stored 925 00:19:52,630 --> 00:19:54,720 for example we can have a stored procedure for getting all the customers 926 00:19:54,720 --> 00:19:54,730 procedure for getting all the customers 927 00:19:54,730 --> 00:19:56,820 procedure for getting all the customers in a given City so we call that 928 00:19:56,820 --> 00:19:56,830 in a given City so we call that 929 00:19:56,830 --> 00:19:58,890 in a given City so we call that procedure and say hey give me all the 930 00:19:58,890 --> 00:19:58,900 procedure and say hey give me all the 931 00:19:58,900 --> 00:20:01,590 procedure and say hey give me all the customers in San Francisco and this will 932 00:20:01,590 --> 00:20:01,600 customers in San Francisco and this will 933 00:20:01,600 --> 00:20:03,090 customers in San Francisco and this will return all the customers in San 934 00:20:03,090 --> 00:20:03,100 return all the customers in San 935 00:20:03,100 --> 00:20:06,960 return all the customers in San Francisco okay now let's expand the 936 00:20:06,960 --> 00:20:06,970 Francisco okay now let's expand the 937 00:20:06,970 --> 00:20:10,440 Francisco okay now let's expand the tables so here are the tables in this 938 00:20:10,440 --> 00:20:10,450 tables so here are the tables in this 939 00:20:10,450 --> 00:20:12,690 tables so here are the tables in this database we have customers we have 940 00:20:12,690 --> 00:20:12,700 database we have customers we have 941 00:20:12,700 --> 00:20:16,800 database we have customers we have orders products shippers and so on now 942 00:20:16,800 --> 00:20:16,810 orders products shippers and so on now 943 00:20:16,810 --> 00:20:19,110 orders products shippers and so on now select this customers table whenever you 944 00:20:19,110 --> 00:20:19,120 select this customers table whenever you 945 00:20:19,120 --> 00:20:21,570 select this customers table whenever you hover your mouse over this item you 946 00:20:21,570 --> 00:20:21,580 hover your mouse over this item you 947 00:20:21,580 --> 00:20:23,550 hover your mouse over this item you should see these three icons on the 948 00:20:23,550 --> 00:20:23,560 should see these three icons on the 949 00:20:23,560 --> 00:20:25,920 should see these three icons on the right side click on the rightmost icon 950 00:20:25,920 --> 00:20:25,930 right side click on the rightmost icon 951 00:20:25,930 --> 00:20:28,820 right side click on the rightmost icon that looks like a table with a Thunder 952 00:20:28,820 --> 00:20:28,830 that looks like a table with a Thunder 953 00:20:28,830 --> 00:20:31,560 that looks like a table with a Thunder with this we can see all the data in 954 00:20:31,560 --> 00:20:31,570 with this we can see all the data in 955 00:20:31,570 --> 00:20:32,550 with this we can see all the data in this table 956 00:20:32,550 --> 00:20:32,560 this table 957 00:20:32,560 --> 00:20:36,150 this table so this is our customers table in this 958 00:20:36,150 --> 00:20:36,160 so this is our customers table in this 959 00:20:36,160 --> 00:20:37,740 so this is our customers table in this table we have these columns like 960 00:20:37,740 --> 00:20:37,750 table we have these columns like 961 00:20:37,750 --> 00:20:39,600 table we have these columns like customer ID which we used to uniquely 962 00:20:39,600 --> 00:20:39,610 customer ID which we used to uniquely 963 00:20:39,610 --> 00:20:41,940 customer ID which we used to uniquely identify customers we also have first 964 00:20:41,940 --> 00:20:41,950 identify customers we also have first 965 00:20:41,950 --> 00:20:45,120 identify customers we also have first name last name birthdate phone address 966 00:20:45,120 --> 00:20:45,130 name last name birthdate phone address 967 00:20:45,130 --> 00:20:47,850 name last name birthdate phone address and so on so these are the columns in 968 00:20:47,850 --> 00:20:47,860 and so on so these are the columns in 969 00:20:47,860 --> 00:20:51,750 and so on so these are the columns in this table and every row is called a 970 00:20:51,750 --> 00:20:51,760 this table and every row is called a 971 00:20:51,760 --> 00:20:54,540 this table and every row is called a record so every row represents one 972 00:20:54,540 --> 00:20:54,550 record so every row represents one 973 00:20:54,550 --> 00:20:55,980 record so every row represents one customer and these are the pieces of 974 00:20:55,980 --> 00:20:55,990 customer and these are the pieces of 975 00:20:55,990 --> 00:20:58,410 customer and these are the pieces of information we know about each customer 976 00:20:58,410 --> 00:20:58,420 information we know about each customer 977 00:20:58,420 --> 00:21:01,230 information we know about each customer now let's look at another table let's 978 00:21:01,230 --> 00:21:01,240 now let's look at another table let's 979 00:21:01,240 --> 00:21:05,070 now let's look at another table let's open the orders table in this table we 980 00:21:05,070 --> 00:21:05,080 open the orders table in this table we 981 00:21:05,080 --> 00:21:06,360 open the orders table in this table we have these columns like order ID 982 00:21:06,360 --> 00:21:06,370 have these columns like order ID 983 00:21:06,370 --> 00:21:10,080 have these columns like order ID customer ID order date status and so on 984 00:21:10,080 --> 00:21:10,090 customer ID order date status and so on 985 00:21:10,090 --> 00:21:13,050 customer ID order date status and so on what is this customer ID here we use 986 00:21:13,050 --> 00:21:13,060 what is this customer ID here we use 987 00:21:13,060 --> 00:21:15,720 what is this customer ID here we use this column to identify who has placed 988 00:21:15,720 --> 00:21:15,730 this column to identify who has placed 989 00:21:15,730 --> 00:21:18,240 this column to identify who has placed each order now what is interesting here 990 00:21:18,240 --> 00:21:18,250 each order now what is interesting here 991 00:21:18,250 --> 00:21:19,680 each order now what is interesting here is that you're referring to this 992 00:21:19,680 --> 00:21:19,690 is that you're referring to this 993 00:21:19,690 --> 00:21:22,230 is that you're referring to this customers using their customer ID which 994 00:21:22,230 --> 00:21:22,240 customers using their customer ID which 995 00:21:22,240 --> 00:21:24,720 customers using their customer ID which uniquely identifies them in other words 996 00:21:24,720 --> 00:21:24,730 uniquely identifies them in other words 997 00:21:24,730 --> 00:21:27,840 uniquely identifies them in other words if John Smith has placed on order we 998 00:21:27,840 --> 00:21:27,850 if John Smith has placed on order we 999 00:21:27,850 --> 00:21:29,970 if John Smith has placed on order we don't store John Smith here the only 1000 00:21:29,970 --> 00:21:29,980 don't store John Smith here the only 1001 00:21:29,980 --> 00:21:32,970 don't store John Smith here the only store John's customer ID why is that 1002 00:21:32,970 --> 00:21:32,980 store John's customer ID why is that 1003 00:21:32,980 --> 00:21:35,850 store John's customer ID why is that here's the reason it is possible that 1004 00:21:35,850 --> 00:21:35,860 here's the reason it is possible that 1005 00:21:35,860 --> 00:21:38,280 here's the reason it is possible that John Smith might have placed multiple 1006 00:21:38,280 --> 00:21:38,290 John Smith might have placed multiple 1007 00:21:38,290 --> 00:21:41,130 John Smith might have placed multiple orders in our system but every time John 1008 00:21:41,130 --> 00:21:41,140 orders in our system but every time John 1009 00:21:41,140 --> 00:21:43,020 orders in our system but every time John places an order we need to look up his 1010 00:21:43,020 --> 00:21:43,030 places an order we need to look up his 1011 00:21:43,030 --> 00:21:45,019 places an order we need to look up his address and phone to ship his 1012 00:21:45,019 --> 00:21:45,029 address and phone to ship his 1013 00:21:45,029 --> 00:21:47,329 address and phone to ship his order now it is possible that some of 1014 00:21:47,329 --> 00:21:47,339 order now it is possible that some of 1015 00:21:47,339 --> 00:21:48,829 order now it is possible that some of this information might change in the 1016 00:21:48,829 --> 00:21:48,839 this information might change in the 1017 00:21:48,839 --> 00:21:51,289 this information might change in the future John might move to a new place or 1018 00:21:51,289 --> 00:21:51,299 future John might move to a new place or 1019 00:21:51,299 --> 00:21:52,549 future John might move to a new place or change his phone number 1020 00:21:52,549 --> 00:21:52,559 change his phone number 1021 00:21:52,559 --> 00:21:54,619 change his phone number he might even change his name if you 1022 00:21:54,619 --> 00:21:54,629 he might even change his name if you 1023 00:21:54,629 --> 00:21:57,109 he might even change his name if you repeat all that information next to each 1024 00:21:57,109 --> 00:21:57,119 repeat all that information next to each 1025 00:21:57,119 --> 00:21:59,179 repeat all that information next to each order then we'll have to come back and 1026 00:21:59,179 --> 00:21:59,189 order then we'll have to come back and 1027 00:21:59,189 --> 00:22:01,419 order then we'll have to come back and make changes in multiple places in 1028 00:22:01,419 --> 00:22:01,429 make changes in multiple places in 1029 00:22:01,429 --> 00:22:04,009 make changes in multiple places in contrast with this design we only store 1030 00:22:04,009 --> 00:22:04,019 contrast with this design we only store 1031 00:22:04,019 --> 00:22:07,369 contrast with this design we only store the idea of John here so anytime we want 1032 00:22:07,369 --> 00:22:07,379 the idea of John here so anytime we want 1033 00:22:07,379 --> 00:22:09,319 the idea of John here so anytime we want to change any information about John 1034 00:22:09,319 --> 00:22:09,329 to change any information about John 1035 00:22:09,329 --> 00:22:12,079 to change any information about John instead of changing that here we go back 1036 00:22:12,079 --> 00:22:12,089 instead of changing that here we go back 1037 00:22:12,089 --> 00:22:15,169 instead of changing that here we go back to our customers table so let's look at 1038 00:22:15,169 --> 00:22:15,179 to our customers table so let's look at 1039 00:22:15,179 --> 00:22:18,319 to our customers table so let's look at the customer with ideas six that is 1040 00:22:18,319 --> 00:22:18,329 the customer with ideas six that is 1041 00:22:18,329 --> 00:22:21,529 the customer with ideas six that is actually called ELCA so here are all the 1042 00:22:21,529 --> 00:22:21,539 actually called ELCA so here are all the 1043 00:22:21,539 --> 00:22:23,419 actually called ELCA so here are all the information about Elka this is her phone 1044 00:22:23,419 --> 00:22:23,429 information about Elka this is her phone 1045 00:22:23,429 --> 00:22:25,429 information about Elka this is her phone number this is her address and by the 1046 00:22:25,429 --> 00:22:25,439 number this is her address and by the 1047 00:22:25,439 --> 00:22:27,049 number this is her address and by the way this is all dummy data that I 1048 00:22:27,049 --> 00:22:27,059 way this is all dummy data that I 1049 00:22:27,059 --> 00:22:29,779 way this is all dummy data that I created using a tool so if any 1050 00:22:29,779 --> 00:22:29,789 created using a tool so if any 1051 00:22:29,789 --> 00:22:31,549 created using a tool so if any information about Elka changes in the 1052 00:22:31,549 --> 00:22:31,559 information about Elka changes in the 1053 00:22:31,559 --> 00:22:33,919 information about Elka changes in the future this is the only place that we 1054 00:22:33,919 --> 00:22:33,929 future this is the only place that we 1055 00:22:33,929 --> 00:22:36,439 future this is the only place that we need to modify so this is how these 1056 00:22:36,439 --> 00:22:36,449 need to modify so this is how these 1057 00:22:36,449 --> 00:22:38,689 need to modify so this is how these databases work we refer to this 1058 00:22:38,689 --> 00:22:38,699 databases work we refer to this 1059 00:22:38,699 --> 00:22:41,869 databases work we refer to this databases as relational databases that 1060 00:22:41,869 --> 00:22:41,879 databases as relational databases that 1061 00:22:41,879 --> 00:22:43,429 databases as relational databases that basically means in this kind of 1062 00:22:43,429 --> 00:22:43,439 basically means in this kind of 1063 00:22:43,439 --> 00:22:45,949 basically means in this kind of databases we have multiple tables that 1064 00:22:45,949 --> 00:22:45,959 databases we have multiple tables that 1065 00:22:45,959 --> 00:22:48,019 databases we have multiple tables that are related to each other using a 1066 00:22:48,019 --> 00:22:48,029 are related to each other using a 1067 00:22:48,029 --> 00:22:50,539 are related to each other using a relationship so internally there is a 1068 00:22:50,539 --> 00:22:50,549 relationship so internally there is a 1069 00:22:50,549 --> 00:22:52,939 relationship so internally there is a relationship between the customers table 1070 00:22:52,939 --> 00:22:52,949 relationship between the customers table 1071 00:22:52,949 --> 00:22:56,299 relationship between the customers table and the orders table so the customer ID 1072 00:22:56,299 --> 00:22:56,309 and the orders table so the customer ID 1073 00:22:56,309 --> 00:22:58,929 and the orders table so the customer ID column and the customers table is 1074 00:22:58,929 --> 00:22:58,939 column and the customers table is 1075 00:22:58,939 --> 00:23:02,659 column and the customers table is related or linked or associated with the 1076 00:23:02,659 --> 00:23:02,669 related or linked or associated with the 1077 00:23:02,669 --> 00:23:05,409 related or linked or associated with the customer ID column in the orders table 1078 00:23:05,409 --> 00:23:05,419 customer ID column in the orders table 1079 00:23:05,419 --> 00:23:08,059 customer ID column in the orders table here's the orders table and here we have 1080 00:23:08,059 --> 00:23:08,069 here's the orders table and here we have 1081 00:23:08,069 --> 00:23:10,969 here's the orders table and here we have the customer ID column so this was a 1082 00:23:10,969 --> 00:23:10,979 the customer ID column so this was a 1083 00:23:10,979 --> 00:23:12,649 the customer ID column so this was a brief introduction to relational 1084 00:23:12,649 --> 00:23:12,659 brief introduction to relational 1085 00:23:12,659 --> 00:23:14,709 brief introduction to relational databases you learn about databases 1086 00:23:14,709 --> 00:23:14,719 databases you learn about databases 1087 00:23:14,719 --> 00:23:19,189 databases you learn about databases tables columns rows and relationships in 1088 00:23:19,189 --> 00:23:19,199 tables columns rows and relationships in 1089 00:23:19,199 --> 00:23:20,749 tables columns rows and relationships in the next section I'm gonna show you how 1090 00:23:20,749 --> 00:23:20,759 the next section I'm gonna show you how 1091 00:23:20,759 --> 00:23:22,909 the next section I'm gonna show you how to retrieve data from a single table in 1092 00:23:22,909 --> 00:23:22,919 to retrieve data from a single table in 1093 00:23:22,919 --> 00:23:25,039 to retrieve data from a single table in this database but before going any 1094 00:23:25,039 --> 00:23:25,049 this database but before going any 1095 00:23:25,049 --> 00:23:27,319 this database but before going any further as an exercise I want you to 1096 00:23:27,319 --> 00:23:27,329 further as an exercise I want you to 1097 00:23:27,329 --> 00:23:30,049 further as an exercise I want you to explore the invoicing database look at 1098 00:23:30,049 --> 00:23:30,059 explore the invoicing database look at 1099 00:23:30,059 --> 00:23:32,089 explore the invoicing database look at all the tables look at all the data to 1100 00:23:32,089 --> 00:23:32,099 all the tables look at all the data to 1101 00:23:32,099 --> 00:23:33,919 all the tables look at all the data to get an idea of the kind of data we have 1102 00:23:33,919 --> 00:23:33,929 get an idea of the kind of data we have 1103 00:23:33,929 --> 00:23:35,899 get an idea of the kind of data we have in this database you're gonna use this 1104 00:23:35,899 --> 00:23:35,909 in this database you're gonna use this 1105 00:23:35,909 --> 00:23:38,659 in this database you're gonna use this database a lot in the future so spend a 1106 00:23:38,659 --> 00:23:38,669 database a lot in the future so spend a 1107 00:23:38,669 --> 00:23:39,979 database a lot in the future so spend a couple of minutes to explore this 1108 00:23:39,979 --> 00:23:39,989 couple of minutes to explore this 1109 00:23:39,989 --> 00:23:45,560 couple of minutes to explore this database 1110 00:23:45,560 --> 00:23:45,570 1111 00:23:45,570 --> 00:23:47,520 in this tutorial I'm going to show you 1112 00:23:47,520 --> 00:23:47,530 in this tutorial I'm going to show you 1113 00:23:47,530 --> 00:23:49,800 in this tutorial I'm going to show you how to retrieve data from a single table 1114 00:23:49,800 --> 00:23:49,810 how to retrieve data from a single table 1115 00:23:49,810 --> 00:23:51,890 how to retrieve data from a single table now look at the Navigator panel 1116 00:23:51,890 --> 00:23:51,900 now look at the Navigator panel 1117 00:23:51,900 --> 00:23:54,120 now look at the Navigator panel currently none of our databases is 1118 00:23:54,120 --> 00:23:54,130 currently none of our databases is 1119 00:23:54,130 --> 00:23:56,730 currently none of our databases is displayed in bold that means none of 1120 00:23:56,730 --> 00:23:56,740 displayed in bold that means none of 1121 00:23:56,740 --> 00:23:58,710 displayed in bold that means none of this databases is selected for querying 1122 00:23:58,710 --> 00:23:58,720 this databases is selected for querying 1123 00:23:58,720 --> 00:24:00,840 this databases is selected for querying so the first step to write a query to 1124 00:24:00,840 --> 00:24:00,850 so the first step to write a query to 1125 00:24:00,850 --> 00:24:03,150 so the first step to write a query to get data from a database is to select a 1126 00:24:03,150 --> 00:24:03,160 get data from a database is to select a 1127 00:24:03,160 --> 00:24:05,580 get data from a database is to select a database the query that will write will 1128 00:24:05,580 --> 00:24:05,590 database the query that will write will 1129 00:24:05,590 --> 00:24:08,550 database the query that will write will be executed against that database in 1130 00:24:08,550 --> 00:24:08,560 be executed against that database in 1131 00:24:08,560 --> 00:24:10,470 be executed against that database in this demo we're gonna use this sequel 1132 00:24:10,470 --> 00:24:10,480 this demo we're gonna use this sequel 1133 00:24:10,480 --> 00:24:14,970 this demo we're gonna use this sequel store database so we type out use sequel 1134 00:24:14,970 --> 00:24:14,980 store database so we type out use sequel 1135 00:24:14,980 --> 00:24:17,940 store database so we type out use sequel on the line store now use is a keyword 1136 00:24:17,940 --> 00:24:17,950 on the line store now use is a keyword 1137 00:24:17,950 --> 00:24:19,680 on the line store now use is a keyword in the sequel language and that's the 1138 00:24:19,680 --> 00:24:19,690 in the sequel language and that's the 1139 00:24:19,690 --> 00:24:22,620 in the sequel language and that's the reason is displayed in blue now sequel 1140 00:24:22,620 --> 00:24:22,630 reason is displayed in blue now sequel 1141 00:24:22,630 --> 00:24:24,390 reason is displayed in blue now sequel is not a case-sensitive language and 1142 00:24:24,390 --> 00:24:24,400 is not a case-sensitive language and 1143 00:24:24,400 --> 00:24:26,250 is not a case-sensitive language and that means we can use uppercase or 1144 00:24:26,250 --> 00:24:26,260 that means we can use uppercase or 1145 00:24:26,260 --> 00:24:28,380 that means we can use uppercase or lowercase characters it doesn't really 1146 00:24:28,380 --> 00:24:28,390 lowercase characters it doesn't really 1147 00:24:28,390 --> 00:24:30,840 lowercase characters it doesn't really matter but as a best practice we should 1148 00:24:30,840 --> 00:24:30,850 matter but as a best practice we should 1149 00:24:30,850 --> 00:24:33,630 matter but as a best practice we should capitalize the sequel keywords and use 1150 00:24:33,630 --> 00:24:33,640 capitalize the sequel keywords and use 1151 00:24:33,640 --> 00:24:35,480 capitalize the sequel keywords and use lowercase characters for anything else 1152 00:24:35,480 --> 00:24:35,490 lowercase characters for anything else 1153 00:24:35,490 --> 00:24:38,010 lowercase characters for anything else so now let's go ahead and execute this 1154 00:24:38,010 --> 00:24:38,020 so now let's go ahead and execute this 1155 00:24:38,020 --> 00:24:41,970 so now let's go ahead and execute this claim all right look the sequel store 1156 00:24:41,970 --> 00:24:41,980 claim all right look the sequel store 1157 00:24:41,980 --> 00:24:45,030 claim all right look the sequel store database is now displayed in bold now in 1158 00:24:45,030 --> 00:24:45,040 database is now displayed in bold now in 1159 00:24:45,040 --> 00:24:47,310 database is now displayed in bold now in MySQL workbench we can also select a 1160 00:24:47,310 --> 00:24:47,320 MySQL workbench we can also select a 1161 00:24:47,320 --> 00:24:49,800 MySQL workbench we can also select a database by double clicking that so now 1162 00:24:49,800 --> 00:24:49,810 database by double clicking that so now 1163 00:24:49,810 --> 00:24:53,040 database by double clicking that so now I double click sequel invoicing and it's 1164 00:24:53,040 --> 00:24:53,050 I double click sequel invoicing and it's 1165 00:24:53,050 --> 00:24:55,110 I double click sequel invoicing and it's the current database now if we run this 1166 00:24:55,110 --> 00:24:55,120 the current database now if we run this 1167 00:24:55,120 --> 00:24:57,810 the current database now if we run this query again the sequel store database 1168 00:24:57,810 --> 00:24:57,820 query again the sequel store database 1169 00:24:57,820 --> 00:25:00,630 query again the sequel store database becomes selected all right now let's 1170 00:25:00,630 --> 00:25:00,640 becomes selected all right now let's 1171 00:25:00,640 --> 00:25:02,640 becomes selected all right now let's write our first query to retrieve all 1172 00:25:02,640 --> 00:25:02,650 write our first query to retrieve all 1173 00:25:02,650 --> 00:25:05,850 write our first query to retrieve all the customers in this database so after 1174 00:25:05,850 --> 00:25:05,860 the customers in this database so after 1175 00:25:05,860 --> 00:25:08,070 the customers in this database so after the use statement we're gonna use the 1176 00:25:08,070 --> 00:25:08,080 the use statement we're gonna use the 1177 00:25:08,080 --> 00:25:10,740 the use statement we're gonna use the Select statement here's the basic syntax 1178 00:25:10,740 --> 00:25:10,750 Select statement here's the basic syntax 1179 00:25:10,750 --> 00:25:13,020 Select statement here's the basic syntax or basic structure of the Select 1180 00:25:13,020 --> 00:25:13,030 or basic structure of the Select 1181 00:25:13,030 --> 00:25:16,170 or basic structure of the Select statement we type out select in front of 1182 00:25:16,170 --> 00:25:16,180 statement we type out select in front of 1183 00:25:16,180 --> 00:25:17,940 statement we type out select in front of that we specified the columns that we 1184 00:25:17,940 --> 00:25:17,950 that we specified the columns that we 1185 00:25:17,950 --> 00:25:19,770 that we specified the columns that we want to retrieve for example we can 1186 00:25:19,770 --> 00:25:19,780 want to retrieve for example we can 1187 00:25:19,780 --> 00:25:21,930 want to retrieve for example we can retrieve the customer ID column as well 1188 00:25:21,930 --> 00:25:21,940 retrieve the customer ID column as well 1189 00:25:21,940 --> 00:25:24,750 retrieve the customer ID column as well as the first name column or we can 1190 00:25:24,750 --> 00:25:24,760 as the first name column or we can 1191 00:25:24,760 --> 00:25:27,200 as the first name column or we can retrieve all columns using an asterisk 1192 00:25:27,200 --> 00:25:27,210 retrieve all columns using an asterisk 1193 00:25:27,210 --> 00:25:30,090 retrieve all columns using an asterisk now after that we use the fron clause 1194 00:25:30,090 --> 00:25:30,100 now after that we use the fron clause 1195 00:25:30,100 --> 00:25:32,460 now after that we use the fron clause and this is where we specify the table 1196 00:25:32,460 --> 00:25:32,470 and this is where we specify the table 1197 00:25:32,470 --> 00:25:34,740 and this is where we specify the table that we want to query in this case the 1198 00:25:34,740 --> 00:25:34,750 that we want to query in this case the 1199 00:25:34,750 --> 00:25:37,320 that we want to query in this case the customers table so this is the simplest 1200 00:25:37,320 --> 00:25:37,330 customers table so this is the simplest 1201 00:25:37,330 --> 00:25:39,240 customers table so this is the simplest query to select all the customers in a 1202 00:25:39,240 --> 00:25:39,250 query to select all the customers in a 1203 00:25:39,250 --> 00:25:41,370 query to select all the customers in a given table now whenever you have 1204 00:25:41,370 --> 00:25:41,380 given table now whenever you have 1205 00:25:41,380 --> 00:25:44,310 given table now whenever you have multiple sequel statements you need to 1206 00:25:44,310 --> 00:25:44,320 multiple sequel statements you need to 1207 00:25:44,320 --> 00:25:46,260 multiple sequel statements you need to terminate each statement using a 1208 00:25:46,260 --> 00:25:46,270 terminate each statement using a 1209 00:25:46,270 --> 00:25:48,930 terminate each statement using a semicolon so look we have a red 1210 00:25:48,930 --> 00:25:48,940 semicolon so look we have a red 1211 00:25:48,940 --> 00:25:50,610 semicolon so look we have a red underline here that indicates an error 1212 00:25:50,610 --> 00:25:50,620 underline here that indicates an error 1213 00:25:50,620 --> 00:25:52,470 underline here that indicates an error if you hover your mouse here you can see 1214 00:25:52,470 --> 00:25:52,480 if you hover your mouse here you can see 1215 00:25:52,480 --> 00:25:54,960 if you hover your mouse here you can see this tooltip saying select is not valid 1216 00:25:54,960 --> 00:25:54,970 this tooltip saying select is not valid 1217 00:25:54,970 --> 00:25:55,300 this tooltip saying select is not valid at the 1218 00:25:55,300 --> 00:25:55,310 at the 1219 00:25:55,310 --> 00:25:57,760 at the position because we didn't terminate the 1220 00:25:57,760 --> 00:25:57,770 position because we didn't terminate the 1221 00:25:57,770 --> 00:25:59,920 position because we didn't terminate the first statement with a semicolon 1222 00:25:59,920 --> 00:25:59,930 first statement with a semicolon 1223 00:25:59,930 --> 00:26:02,620 first statement with a semicolon okay now let's execute this query one 1224 00:26:02,620 --> 00:26:02,630 okay now let's execute this query one 1225 00:26:02,630 --> 00:26:04,630 okay now let's execute this query one more time once again we can click on 1226 00:26:04,630 --> 00:26:04,640 more time once again we can click on 1227 00:26:04,640 --> 00:26:06,730 more time once again we can click on this button here or we can use a 1228 00:26:06,730 --> 00:26:06,740 this button here or we can use a 1229 00:26:06,740 --> 00:26:09,160 this button here or we can use a shortcut so look at the query menu on 1230 00:26:09,160 --> 00:26:09,170 shortcut so look at the query menu on 1231 00:26:09,170 --> 00:26:11,790 shortcut so look at the query menu on the top the first item is execute now 1232 00:26:11,790 --> 00:26:11,800 the top the first item is execute now 1233 00:26:11,800 --> 00:26:14,230 the top the first item is execute now here's the shortcut for this command on 1234 00:26:14,230 --> 00:26:14,240 here's the shortcut for this command on 1235 00:26:14,240 --> 00:26:18,130 here's the shortcut for this command on Mac it's shift command and enter on 1236 00:26:18,130 --> 00:26:18,140 Mac it's shift command and enter on 1237 00:26:18,140 --> 00:26:19,870 Mac it's shift command and enter on Windows it's gonna be different honestly 1238 00:26:19,870 --> 00:26:19,880 Windows it's gonna be different honestly 1239 00:26:19,880 --> 00:26:22,540 Windows it's gonna be different honestly I'm not sure so whatever it is use that 1240 00:26:22,540 --> 00:26:22,550 I'm not sure so whatever it is use that 1241 00:26:22,550 --> 00:26:25,090 I'm not sure so whatever it is use that so I'm gonna press shift command and 1242 00:26:25,090 --> 00:26:25,100 so I'm gonna press shift command and 1243 00:26:25,100 --> 00:26:29,410 so I'm gonna press shift command and enter and here are all the customers and 1244 00:26:29,410 --> 00:26:29,420 enter and here are all the customers and 1245 00:26:29,420 --> 00:26:32,770 enter and here are all the customers and it's table so this select statement has 1246 00:26:32,770 --> 00:26:32,780 it's table so this select statement has 1247 00:26:32,780 --> 00:26:35,500 it's table so this select statement has two clauses the Select Clause and the 1248 00:26:35,500 --> 00:26:35,510 two clauses the Select Clause and the 1249 00:26:35,510 --> 00:26:38,080 two clauses the Select Clause and the from clause but there are other clauses 1250 00:26:38,080 --> 00:26:38,090 from clause but there are other clauses 1251 00:26:38,090 --> 00:26:40,480 from clause but there are other clauses that we can use to filter and sort data 1252 00:26:40,480 --> 00:26:40,490 that we can use to filter and sort data 1253 00:26:40,490 --> 00:26:43,390 that we can use to filter and sort data for example we can use the where Clause 1254 00:26:43,390 --> 00:26:43,400 for example we can use the where Clause 1255 00:26:43,400 --> 00:26:46,570 for example we can use the where Clause to filter the result and get the 1256 00:26:46,570 --> 00:26:46,580 to filter the result and get the 1257 00:26:46,580 --> 00:26:49,540 to filter the result and get the customer with ID 1 so we can write an 1258 00:26:49,540 --> 00:26:49,550 customer with ID 1 so we can write an 1259 00:26:49,550 --> 00:26:52,000 customer with ID 1 so we can write an expression like this where customer 1260 00:26:52,000 --> 00:26:52,010 expression like this where customer 1261 00:26:52,010 --> 00:26:55,450 expression like this where customer underlined ID equals 1 now when we 1262 00:26:55,450 --> 00:26:55,460 underlined ID equals 1 now when we 1263 00:26:55,460 --> 00:26:58,660 underlined ID equals 1 now when we execute this query will only get the 1264 00:26:58,660 --> 00:26:58,670 execute this query will only get the 1265 00:26:58,670 --> 00:27:02,140 execute this query will only get the customer with ID 1 so this is the where 1266 00:27:02,140 --> 00:27:02,150 customer with ID 1 so this is the where 1267 00:27:02,150 --> 00:27:04,630 customer with ID 1 so this is the where clause we can also sort the data 1268 00:27:04,630 --> 00:27:04,640 clause we can also sort the data 1269 00:27:04,640 --> 00:27:08,050 clause we can also sort the data so after where we use the order by 1270 00:27:08,050 --> 00:27:08,060 so after where we use the order by 1271 00:27:08,060 --> 00:27:10,660 so after where we use the order by clause and here we specify the columns 1272 00:27:10,660 --> 00:27:10,670 clause and here we specify the columns 1273 00:27:10,670 --> 00:27:13,000 clause and here we specify the columns that we want to sort the result on let's 1274 00:27:13,000 --> 00:27:13,010 that we want to sort the result on let's 1275 00:27:13,010 --> 00:27:14,470 that we want to sort the result on let's say we want to sort this customers by 1276 00:27:14,470 --> 00:27:14,480 say we want to sort this customers by 1277 00:27:14,480 --> 00:27:16,240 say we want to sort this customers by their first name so we type out first 1278 00:27:16,240 --> 00:27:16,250 their first name so we type out first 1279 00:27:16,250 --> 00:27:18,490 their first name so we type out first underline name that is the name of one 1280 00:27:18,490 --> 00:27:18,500 underline name that is the name of one 1281 00:27:18,500 --> 00:27:21,340 underline name that is the name of one of the columns in this table right now 1282 00:27:21,340 --> 00:27:21,350 of the columns in this table right now 1283 00:27:21,350 --> 00:27:23,170 of the columns in this table right now if we execute this query this order by 1284 00:27:23,170 --> 00:27:23,180 if we execute this query this order by 1285 00:27:23,180 --> 00:27:25,240 if we execute this query this order by it doesn't really have any impact 1286 00:27:25,240 --> 00:27:25,250 it doesn't really have any impact 1287 00:27:25,250 --> 00:27:27,580 it doesn't really have any impact because we only get one record in the 1288 00:27:27,580 --> 00:27:27,590 because we only get one record in the 1289 00:27:27,590 --> 00:27:28,090 because we only get one record in the result 1290 00:27:28,090 --> 00:27:28,100 result 1291 00:27:28,100 --> 00:27:30,940 result so let me temporarily take out the where 1292 00:27:30,940 --> 00:27:30,950 so let me temporarily take out the where 1293 00:27:30,950 --> 00:27:33,820 so let me temporarily take out the where clause to do that we can put two hyphens 1294 00:27:33,820 --> 00:27:33,830 clause to do that we can put two hyphens 1295 00:27:33,830 --> 00:27:36,220 clause to do that we can put two hyphens in front of this line now this line is 1296 00:27:36,220 --> 00:27:36,230 in front of this line now this line is 1297 00:27:36,230 --> 00:27:38,800 in front of this line now this line is treated as a comment which means the 1298 00:27:38,800 --> 00:27:38,810 treated as a comment which means the 1299 00:27:38,810 --> 00:27:40,860 treated as a comment which means the sequel engine is not gonna execute this 1300 00:27:40,860 --> 00:27:40,870 sequel engine is not gonna execute this 1301 00:27:40,870 --> 00:27:42,010 sequel engine is not gonna execute this okay 1302 00:27:42,010 --> 00:27:42,020 okay 1303 00:27:42,020 --> 00:27:43,930 okay so let's execute this query one more 1304 00:27:43,930 --> 00:27:43,940 so let's execute this query one more 1305 00:27:43,940 --> 00:27:47,140 so let's execute this query one more time now all the customers that we get 1306 00:27:47,140 --> 00:27:47,150 time now all the customers that we get 1307 00:27:47,150 --> 00:27:50,770 time now all the customers that we get are sorted based on their first name so 1308 00:27:50,770 --> 00:27:50,780 are sorted based on their first name so 1309 00:27:50,780 --> 00:27:53,560 are sorted based on their first name so that's the basic idea now over the next 1310 00:27:53,560 --> 00:27:53,570 that's the basic idea now over the next 1311 00:27:53,570 --> 00:27:54,670 that's the basic idea now over the next few tutorials you're gonna learn more 1312 00:27:54,670 --> 00:27:54,680 few tutorials you're gonna learn more 1313 00:27:54,680 --> 00:27:57,070 few tutorials you're gonna learn more about each of these classes in detail 1314 00:27:57,070 --> 00:27:57,080 about each of these classes in detail 1315 00:27:57,080 --> 00:27:58,900 about each of these classes in detail but what you need to take away in this 1316 00:27:58,900 --> 00:27:58,910 but what you need to take away in this 1317 00:27:58,910 --> 00:28:01,060 but what you need to take away in this tutorial is that these three clauses 1318 00:28:01,060 --> 00:28:01,070 tutorial is that these three clauses 1319 00:28:01,070 --> 00:28:05,320 tutorial is that these three clauses from where an order by are optional as 1320 00:28:05,320 --> 00:28:05,330 from where an order by are optional as 1321 00:28:05,330 --> 00:28:06,730 from where an order by are optional as you can see in this example I'm not 1322 00:28:06,730 --> 00:28:06,740 you can see in this example I'm not 1323 00:28:06,740 --> 00:28:08,590 you can see in this example I'm not using the where clause we can 1324 00:28:08,590 --> 00:28:08,600 using the where clause we can 1325 00:28:08,600 --> 00:28:11,410 using the where clause we can so comment out the order by Clause we 1326 00:28:11,410 --> 00:28:11,420 so comment out the order by Clause we 1327 00:28:11,420 --> 00:28:14,470 so comment out the order by Clause we can also comment out the front clause so 1328 00:28:14,470 --> 00:28:14,480 can also comment out the front clause so 1329 00:28:14,480 --> 00:28:16,270 can also comment out the front clause so instead of selecting all the columns in 1330 00:28:16,270 --> 00:28:16,280 instead of selecting all the columns in 1331 00:28:16,280 --> 00:28:18,400 instead of selecting all the columns in a given table we can select some values 1332 00:28:18,400 --> 00:28:18,410 a given table we can select some values 1333 00:28:18,410 --> 00:28:21,040 a given table we can select some values like 1 & 2 now if you execute this query 1334 00:28:21,040 --> 00:28:21,050 like 1 & 2 now if you execute this query 1335 00:28:21,050 --> 00:28:23,140 like 1 & 2 now if you execute this query one more time in the result we get 1336 00:28:23,140 --> 00:28:23,150 one more time in the result we get 1337 00:28:23,150 --> 00:28:26,200 one more time in the result we get something like this two columns called 1 1338 00:28:26,200 --> 00:28:26,210 something like this two columns called 1 1339 00:28:26,210 --> 00:28:28,120 something like this two columns called 1 & 2 & in these columns we have these 1340 00:28:28,120 --> 00:28:28,130 & 2 & in these columns we have these 1341 00:28:28,130 --> 00:28:31,180 & 2 & in these columns we have these values so all these clauses are optional 1342 00:28:31,180 --> 00:28:31,190 values so all these clauses are optional 1343 00:28:31,190 --> 00:28:33,280 values so all these clauses are optional but in the real world we quite often use 1344 00:28:33,280 --> 00:28:33,290 but in the real world we quite often use 1345 00:28:33,290 --> 00:28:35,110 but in the real world we quite often use all of them but what you need to 1346 00:28:35,110 --> 00:28:35,120 all of them but what you need to 1347 00:28:35,120 --> 00:28:36,700 all of them but what you need to understand here is that the order of 1348 00:28:36,700 --> 00:28:36,710 understand here is that the order of 1349 00:28:36,710 --> 00:28:39,100 understand here is that the order of this clause is matters so we always have 1350 00:28:39,100 --> 00:28:39,110 this clause is matters so we always have 1351 00:28:39,110 --> 00:28:41,620 this clause is matters so we always have select first then we have from then 1352 00:28:41,620 --> 00:28:41,630 select first then we have from then 1353 00:28:41,630 --> 00:28:44,530 select first then we have from then where and finally order by we cannot 1354 00:28:44,530 --> 00:28:44,540 where and finally order by we cannot 1355 00:28:44,540 --> 00:28:46,210 where and finally order by we cannot change the order of these classes 1356 00:28:46,210 --> 00:28:46,220 change the order of these classes 1357 00:28:46,220 --> 00:28:48,370 change the order of these classes otherwise we get a syntax error which 1358 00:28:48,370 --> 00:28:48,380 otherwise we get a syntax error which 1359 00:28:48,380 --> 00:28:50,620 otherwise we get a syntax error which basically means the syntax or the 1360 00:28:50,620 --> 00:28:50,630 basically means the syntax or the 1361 00:28:50,630 --> 00:28:52,960 basically means the syntax or the grammar or the structure of our sequel 1362 00:28:52,960 --> 00:28:52,970 grammar or the structure of our sequel 1363 00:28:52,970 --> 00:28:55,420 grammar or the structure of our sequel statement is incorrect so it can't be 1364 00:28:55,420 --> 00:28:55,430 statement is incorrect so it can't be 1365 00:28:55,430 --> 00:28:57,550 statement is incorrect so it can't be executed and one last thing before we 1366 00:28:57,550 --> 00:28:57,560 executed and one last thing before we 1367 00:28:57,560 --> 00:28:59,950 executed and one last thing before we finish this tutorial in this example you 1368 00:28:59,950 --> 00:28:59,960 finish this tutorial in this example you 1369 00:28:59,960 --> 00:29:01,900 finish this tutorial in this example you can see I've listed all these clauses on 1370 00:29:01,900 --> 00:29:01,910 can see I've listed all these clauses on 1371 00:29:01,910 --> 00:29:03,820 can see I've listed all these clauses on a new line but technically you don't 1372 00:29:03,820 --> 00:29:03,830 a new line but technically you don't 1373 00:29:03,830 --> 00:29:05,560 a new line but technically you don't have to do this because line breaks 1374 00:29:05,560 --> 00:29:05,570 have to do this because line breaks 1375 00:29:05,570 --> 00:29:08,140 have to do this because line breaks white spaces and tabs are ignored when 1376 00:29:08,140 --> 00:29:08,150 white spaces and tabs are ignored when 1377 00:29:08,150 --> 00:29:11,290 white spaces and tabs are ignored when executing sequel statements so we could 1378 00:29:11,290 --> 00:29:11,300 executing sequel statements so we could 1379 00:29:11,300 --> 00:29:13,990 executing sequel statements so we could come back here and put from in front of 1380 00:29:13,990 --> 00:29:14,000 come back here and put from in front of 1381 00:29:14,000 --> 00:29:16,690 come back here and put from in front of select so select star from customers all 1382 00:29:16,690 --> 00:29:16,700 select so select star from customers all 1383 00:29:16,700 --> 00:29:18,550 select so select star from customers all in one line and that's perfectly fine 1384 00:29:18,550 --> 00:29:18,560 in one line and that's perfectly fine 1385 00:29:18,560 --> 00:29:21,130 in one line and that's perfectly fine for simple queries but as your queries 1386 00:29:21,130 --> 00:29:21,140 for simple queries but as your queries 1387 00:29:21,140 --> 00:29:23,620 for simple queries but as your queries get more complex it's better to put each 1388 00:29:23,620 --> 00:29:23,630 get more complex it's better to put each 1389 00:29:23,630 --> 00:29:26,440 get more complex it's better to put each Clause on a new line so that's all for 1390 00:29:26,440 --> 00:29:26,450 Clause on a new line so that's all for 1391 00:29:26,450 --> 00:29:27,040 Clause on a new line so that's all for this tutorial 1392 00:29:27,040 --> 00:29:27,050 this tutorial 1393 00:29:27,050 --> 00:29:29,290 this tutorial in the next tutorial we'll explore the 1394 00:29:29,290 --> 00:29:29,300 in the next tutorial we'll explore the 1395 00:29:29,300 --> 00:29:37,120 in the next tutorial we'll explore the seller clause in detail in this tutorial 1396 00:29:37,120 --> 00:29:37,130 seller clause in detail in this tutorial 1397 00:29:37,130 --> 00:29:39,220 seller clause in detail in this tutorial we're gonna look at the Select Clause in 1398 00:29:39,220 --> 00:29:39,230 we're gonna look at the Select Clause in 1399 00:29:39,230 --> 00:29:42,160 we're gonna look at the Select Clause in detail so since our current database is 1400 00:29:42,160 --> 00:29:42,170 detail so since our current database is 1401 00:29:42,170 --> 00:29:44,920 detail so since our current database is seacoast or to clean things up I'm gonna 1402 00:29:44,920 --> 00:29:44,930 seacoast or to clean things up I'm gonna 1403 00:29:44,930 --> 00:29:46,690 seacoast or to clean things up I'm gonna remove the first statement you don't 1404 00:29:46,690 --> 00:29:46,700 remove the first statement you don't 1405 00:29:46,700 --> 00:29:49,710 remove the first statement you don't really need it now also I'm gonna delete 1406 00:29:49,710 --> 00:29:49,720 really need it now also I'm gonna delete 1407 00:29:49,720 --> 00:29:52,360 really need it now also I'm gonna delete these two comments we just want to focus 1408 00:29:52,360 --> 00:29:52,370 these two comments we just want to focus 1409 00:29:52,370 --> 00:29:56,290 these two comments we just want to focus on the Select clause alright so what can 1410 00:29:56,290 --> 00:29:56,300 on the Select clause alright so what can 1411 00:29:56,300 --> 00:29:58,150 on the Select clause alright so what can we do with the Select clause well in the 1412 00:29:58,150 --> 00:29:58,160 we do with the Select clause well in the 1413 00:29:58,160 --> 00:29:59,800 we do with the Select clause well in the last tutorial you'll learn that if we 1414 00:29:59,800 --> 00:29:59,810 last tutorial you'll learn that if we 1415 00:29:59,810 --> 00:30:02,050 last tutorial you'll learn that if we use an asterisk this will return all the 1416 00:30:02,050 --> 00:30:02,060 use an asterisk this will return all the 1417 00:30:02,060 --> 00:30:04,540 use an asterisk this will return all the columns alternatively we can specify the 1418 00:30:04,540 --> 00:30:04,550 columns alternatively we can specify the 1419 00:30:04,550 --> 00:30:06,280 columns alternatively we can specify the columns that we want and this is helpful 1420 00:30:06,280 --> 00:30:06,290 columns that we want and this is helpful 1421 00:30:06,290 --> 00:30:08,440 columns that we want and this is helpful in situations where you have a big table 1422 00:30:08,440 --> 00:30:08,450 in situations where you have a big table 1423 00:30:08,450 --> 00:30:10,660 in situations where you have a big table with so many columns and perhaps 1424 00:30:10,660 --> 00:30:10,670 with so many columns and perhaps 1425 00:30:10,670 --> 00:30:13,000 with so many columns and perhaps millions of Records if you want to bring 1426 00:30:13,000 --> 00:30:13,010 millions of Records if you want to bring 1427 00:30:13,010 --> 00:30:15,250 millions of Records if you want to bring back all that data that's gonna put a 1428 00:30:15,250 --> 00:30:15,260 back all that data that's gonna put a 1429 00:30:15,260 --> 00:30:17,020 back all that data that's gonna put a lot of pressure on the database server 1430 00:30:17,020 --> 00:30:17,030 lot of pressure on the database server 1431 00:30:17,030 --> 00:30:19,660 lot of pressure on the database server in this case MySQL as well as the 1432 00:30:19,660 --> 00:30:19,670 in this case MySQL as well as the 1433 00:30:19,670 --> 00:30:22,240 in this case MySQL as well as the network so that's when we explicit 1434 00:30:22,240 --> 00:30:22,250 network so that's when we explicit 1435 00:30:22,250 --> 00:30:24,750 network so that's when we explicit specify the columns that we want to get 1436 00:30:24,750 --> 00:30:24,760 specify the columns that we want to get 1437 00:30:24,760 --> 00:30:27,880 specify the columns that we want to get let's say we want to get the first name 1438 00:30:27,880 --> 00:30:27,890 let's say we want to get the first name 1439 00:30:27,890 --> 00:30:32,350 let's say we want to get the first name and last name columns execute the query 1440 00:30:32,350 --> 00:30:32,360 and last name columns execute the query 1441 00:30:32,360 --> 00:30:35,890 and last name columns execute the query as you can see we only get these two 1442 00:30:35,890 --> 00:30:35,900 as you can see we only get these two 1443 00:30:35,900 --> 00:30:37,960 as you can see we only get these two columns and they're in the same order 1444 00:30:37,960 --> 00:30:37,970 columns and they're in the same order 1445 00:30:37,970 --> 00:30:40,420 columns and they're in the same order you specified here so if we change the 1446 00:30:40,420 --> 00:30:40,430 you specified here so if we change the 1447 00:30:40,430 --> 00:30:43,140 you specified here so if we change the order and put the last name first and 1448 00:30:43,140 --> 00:30:43,150 order and put the last name first and 1449 00:30:43,150 --> 00:30:46,030 order and put the last name first and execute the query again now you can see 1450 00:30:46,030 --> 00:30:46,040 execute the query again now you can see 1451 00:30:46,040 --> 00:30:48,850 execute the query again now you can see the last name column comes first now 1452 00:30:48,850 --> 00:30:48,860 the last name column comes first now 1453 00:30:48,860 --> 00:30:51,730 the last name column comes first now let's add a new column to the end let's 1454 00:30:51,730 --> 00:30:51,740 let's add a new column to the end let's 1455 00:30:51,740 --> 00:30:53,620 let's add a new column to the end let's get the point for each customer as well 1456 00:30:53,620 --> 00:30:53,630 get the point for each customer as well 1457 00:30:53,630 --> 00:30:56,410 get the point for each customer as well we run the query so these are the points 1458 00:30:56,410 --> 00:30:56,420 we run the query so these are the points 1459 00:30:56,420 --> 00:30:58,990 we run the query so these are the points for each customer which are calculated 1460 00:30:58,990 --> 00:30:59,000 for each customer which are calculated 1461 00:30:59,000 --> 00:31:01,390 for each customer which are calculated based on their shopping now let's say we 1462 00:31:01,390 --> 00:31:01,400 based on their shopping now let's say we 1463 00:31:01,400 --> 00:31:02,950 based on their shopping now let's say we want to get these points and put them in 1464 00:31:02,950 --> 00:31:02,960 want to get these points and put them in 1465 00:31:02,960 --> 00:31:05,110 want to get these points and put them in a mathematical formula to calculate the 1466 00:31:05,110 --> 00:31:05,120 a mathematical formula to calculate the 1467 00:31:05,120 --> 00:31:06,580 a mathematical formula to calculate the discount that we can give to each 1468 00:31:06,580 --> 00:31:06,590 discount that we can give to each 1469 00:31:06,590 --> 00:31:08,740 discount that we can give to each customer so here we can use an 1470 00:31:08,740 --> 00:31:08,750 customer so here we can use an 1471 00:31:08,750 --> 00:31:11,140 customer so here we can use an arithmetic expression let's say points 1472 00:31:11,140 --> 00:31:11,150 arithmetic expression let's say points 1473 00:31:11,150 --> 00:31:13,810 arithmetic expression let's say points plus 10 this is an arithmetic expression 1474 00:31:13,810 --> 00:31:13,820 plus 10 this is an arithmetic expression 1475 00:31:13,820 --> 00:31:16,600 plus 10 this is an arithmetic expression so now if you execute this query for the 1476 00:31:16,600 --> 00:31:16,610 so now if you execute this query for the 1477 00:31:16,610 --> 00:31:18,490 so now if you execute this query for the first record you can see that their 1478 00:31:18,490 --> 00:31:18,500 first record you can see that their 1479 00:31:18,500 --> 00:31:22,240 first record you can see that their point will end up being 2 2 8 3 let's 1480 00:31:22,240 --> 00:31:22,250 point will end up being 2 2 8 3 let's 1481 00:31:22,250 --> 00:31:24,640 point will end up being 2 2 8 3 let's run the query one more time there you go 1482 00:31:24,640 --> 00:31:24,650 run the query one more time there you go 1483 00:31:24,650 --> 00:31:26,680 run the query one more time there you go now we can put the original points 1484 00:31:26,680 --> 00:31:26,690 now we can put the original points 1485 00:31:26,690 --> 00:31:28,810 now we can put the original points column here for clarity some points 1486 00:31:28,810 --> 00:31:28,820 column here for clarity some points 1487 00:31:28,820 --> 00:31:32,200 column here for clarity some points comma points plus 10 let's run the query 1488 00:31:32,200 --> 00:31:32,210 comma points plus 10 let's run the query 1489 00:31:32,210 --> 00:31:34,570 comma points plus 10 let's run the query one more time now we can see the 1490 00:31:34,570 --> 00:31:34,580 one more time now we can see the 1491 00:31:34,580 --> 00:31:36,460 one more time now we can see the original points and next to that you can 1492 00:31:36,460 --> 00:31:36,470 original points and next to that you can 1493 00:31:36,470 --> 00:31:38,530 original points and next to that you can see the value that we're gonna use to 1494 00:31:38,530 --> 00:31:38,540 see the value that we're gonna use to 1495 00:31:38,540 --> 00:31:40,930 see the value that we're gonna use to calculate the discount now here we're 1496 00:31:40,930 --> 00:31:40,940 calculate the discount now here we're 1497 00:31:40,940 --> 00:31:42,910 calculate the discount now here we're using the plus operator which is for 1498 00:31:42,910 --> 00:31:42,920 using the plus operator which is for 1499 00:31:42,920 --> 00:31:45,270 using the plus operator which is for addition we also have multiplication 1500 00:31:45,270 --> 00:31:45,280 addition we also have multiplication 1501 00:31:45,280 --> 00:31:48,820 addition we also have multiplication division subtraction and modular which 1502 00:31:48,820 --> 00:31:48,830 division subtraction and modular which 1503 00:31:48,830 --> 00:31:51,040 division subtraction and modular which is the remainder of the division so 1504 00:31:51,040 --> 00:31:51,050 is the remainder of the division so 1505 00:31:51,050 --> 00:31:52,240 is the remainder of the division so let's change this to something more 1506 00:31:52,240 --> 00:31:52,250 let's change this to something more 1507 00:31:52,250 --> 00:31:54,220 let's change this to something more complex let's say we want to get the 1508 00:31:54,220 --> 00:31:54,230 complex let's say we want to get the 1509 00:31:54,230 --> 00:31:57,600 complex let's say we want to get the points multiplied by 10 and then add 1510 00:31:57,600 --> 00:31:57,610 points multiplied by 10 and then add 1511 00:31:57,610 --> 00:32:01,120 points multiplied by 10 and then add hundred to it now you can immediately 1512 00:32:01,120 --> 00:32:01,130 hundred to it now you can immediately 1513 00:32:01,130 --> 00:32:03,880 hundred to it now you can immediately see that this line 1 is getting too long 1514 00:32:03,880 --> 00:32:03,890 see that this line 1 is getting too long 1515 00:32:03,890 --> 00:32:06,220 see that this line 1 is getting too long and it doesn't fit on the screen in 1516 00:32:06,220 --> 00:32:06,230 and it doesn't fit on the screen in 1517 00:32:06,230 --> 00:32:08,320 and it doesn't fit on the screen in situations like this you can break up 1518 00:32:08,320 --> 00:32:08,330 situations like this you can break up 1519 00:32:08,330 --> 00:32:10,870 situations like this you can break up the Select Clause by placing each column 1520 00:32:10,870 --> 00:32:10,880 the Select Clause by placing each column 1521 00:32:10,880 --> 00:32:14,410 the Select Clause by placing each column on a new line so select last name then 1522 00:32:14,410 --> 00:32:14,420 on a new line so select last name then 1523 00:32:14,420 --> 00:32:18,190 on a new line so select last name then first name points and finally points 1524 00:32:18,190 --> 00:32:18,200 first name points and finally points 1525 00:32:18,200 --> 00:32:22,420 first name points and finally points times 10 plus 100 so let's execute this 1526 00:32:22,420 --> 00:32:22,430 times 10 plus 100 so let's execute this 1527 00:32:22,430 --> 00:32:25,690 times 10 plus 100 so let's execute this query one more time so this is our new 1528 00:32:25,690 --> 00:32:25,700 query one more time so this is our new 1529 00:32:25,700 --> 00:32:28,240 query one more time so this is our new column with the new calculated value now 1530 00:32:28,240 --> 00:32:28,250 column with the new calculated value now 1531 00:32:28,250 --> 00:32:29,680 column with the new calculated value now one thing you need to understand in this 1532 00:32:29,680 --> 00:32:29,690 one thing you need to understand in this 1533 00:32:29,690 --> 00:32:32,290 one thing you need to understand in this arithmetic expression is the order of 1534 00:32:32,290 --> 00:32:32,300 arithmetic expression is the order of 1535 00:32:32,300 --> 00:32:34,840 arithmetic expression is the order of operators and this is based on the order 1536 00:32:34,840 --> 00:32:34,850 operators and this is based on the order 1537 00:32:34,850 --> 00:32:36,220 operators and this is based on the order of operators in 1538 00:32:36,220 --> 00:32:36,230 of operators in 1539 00:32:36,230 --> 00:32:39,610 of operators in so in math the multiplication and 1540 00:32:39,610 --> 00:32:39,620 so in math the multiplication and 1541 00:32:39,620 --> 00:32:41,950 so in math the multiplication and division operators have higher order or 1542 00:32:41,950 --> 00:32:41,960 division operators have higher order or 1543 00:32:41,960 --> 00:32:44,320 division operators have higher order or higher precedence than addition and 1544 00:32:44,320 --> 00:32:44,330 higher precedence than addition and 1545 00:32:44,330 --> 00:32:47,350 higher precedence than addition and subtraction so in this expression first 1546 00:32:47,350 --> 00:32:47,360 subtraction so in this expression first 1547 00:32:47,360 --> 00:32:50,590 subtraction so in this expression first points is multiplied by 10 and then the 1548 00:32:50,590 --> 00:32:50,600 points is multiplied by 10 and then the 1549 00:32:50,600 --> 00:32:53,740 points is multiplied by 10 and then the result is added to a hundred like if 1550 00:32:53,740 --> 00:32:53,750 result is added to a hundred like if 1551 00:32:53,750 --> 00:32:55,180 result is added to a hundred like if this is not what you want you can always 1552 00:32:55,180 --> 00:32:55,190 this is not what you want you can always 1553 00:32:55,190 --> 00:32:57,820 this is not what you want you can always change the order by using parentheses as 1554 00:32:57,820 --> 00:32:57,830 change the order by using parentheses as 1555 00:32:57,830 --> 00:33:00,039 change the order by using parentheses as an example let's change this 1556 00:33:00,039 --> 00:33:00,049 an example let's change this 1557 00:33:00,049 --> 00:33:03,880 an example let's change this multiplication to addition and then put 1558 00:33:03,880 --> 00:33:03,890 multiplication to addition and then put 1559 00:33:03,890 --> 00:33:05,919 multiplication to addition and then put that multiplication here in this 1560 00:33:05,919 --> 00:33:05,929 that multiplication here in this 1561 00:33:05,929 --> 00:33:08,740 that multiplication here in this expression first ten is multiplied by 1562 00:33:08,740 --> 00:33:08,750 expression first ten is multiplied by 1563 00:33:08,750 --> 00:33:11,650 expression first ten is multiplied by 100 and then the result is added to the 1564 00:33:11,650 --> 00:33:11,660 100 and then the result is added to the 1565 00:33:11,660 --> 00:33:13,780 100 and then the result is added to the point now let's say this is not what we 1566 00:33:13,780 --> 00:33:13,790 point now let's say this is not what we 1567 00:33:13,790 --> 00:33:16,240 point now let's say this is not what we want so we can change the order by using 1568 00:33:16,240 --> 00:33:16,250 want so we can change the order by using 1569 00:33:16,250 --> 00:33:20,919 want so we can change the order by using parentheses here with this parentheses 1570 00:33:20,919 --> 00:33:20,929 parentheses here with this parentheses 1571 00:33:20,929 --> 00:33:22,060 parentheses here with this parentheses first 1572 00:33:22,060 --> 00:33:22,070 first 1573 00:33:22,070 --> 00:33:24,400 first we get the points attend to them and 1574 00:33:24,400 --> 00:33:24,410 we get the points attend to them and 1575 00:33:24,410 --> 00:33:27,970 we get the points attend to them and then multiply the result by 100 so these 1576 00:33:27,970 --> 00:33:27,980 then multiply the result by 100 so these 1577 00:33:27,980 --> 00:33:30,280 then multiply the result by 100 so these parentheses are useful for changing the 1578 00:33:30,280 --> 00:33:30,290 parentheses are useful for changing the 1579 00:33:30,290 --> 00:33:32,440 parentheses are useful for changing the order of operations as well as adding 1580 00:33:32,440 --> 00:33:32,450 order of operations as well as adding 1581 00:33:32,450 --> 00:33:34,419 order of operations as well as adding clarity to our code so someone else 1582 00:33:34,419 --> 00:33:34,429 clarity to our code so someone else 1583 00:33:34,429 --> 00:33:36,340 clarity to our code so someone else reading this code can easily understand 1584 00:33:36,340 --> 00:33:36,350 reading this code can easily understand 1585 00:33:36,350 --> 00:33:38,950 reading this code can easily understand the order of these operations now let's 1586 00:33:38,950 --> 00:33:38,960 the order of these operations now let's 1587 00:33:38,960 --> 00:33:41,890 the order of these operations now let's execute this query one more time all 1588 00:33:41,890 --> 00:33:41,900 execute this query one more time all 1589 00:33:41,900 --> 00:33:43,600 execute this query one more time all right now look at the name of this 1590 00:33:43,600 --> 00:33:43,610 right now look at the name of this 1591 00:33:43,610 --> 00:33:46,150 right now look at the name of this column here it's said to the expression 1592 00:33:46,150 --> 00:33:46,160 column here it's said to the expression 1593 00:33:46,160 --> 00:33:48,549 column here it's said to the expression that we have on line 5 that doesn't 1594 00:33:48,549 --> 00:33:48,559 that we have on line 5 that doesn't 1595 00:33:48,559 --> 00:33:50,560 that we have on line 5 that doesn't quite make sense we want to have a clear 1596 00:33:50,560 --> 00:33:50,570 quite make sense we want to have a clear 1597 00:33:50,570 --> 00:33:53,200 quite make sense we want to have a clear descriptive name so we can give this 1598 00:33:53,200 --> 00:33:53,210 descriptive name so we can give this 1599 00:33:53,210 --> 00:33:56,500 descriptive name so we can give this column and alias using the as keyword so 1600 00:33:56,500 --> 00:33:56,510 column and alias using the as keyword so 1601 00:33:56,510 --> 00:33:58,870 column and alias using the as keyword so as and then we give it a name like 1602 00:33:58,870 --> 00:33:58,880 as and then we give it a name like 1603 00:33:58,880 --> 00:34:03,130 as and then we give it a name like discount discount underline factor let's 1604 00:34:03,130 --> 00:34:03,140 discount discount underline factor let's 1605 00:34:03,140 --> 00:34:06,280 discount discount underline factor let's run the query again now the name of this 1606 00:34:06,280 --> 00:34:06,290 run the query again now the name of this 1607 00:34:06,290 --> 00:34:08,710 run the query again now the name of this column is changed so this is the benefit 1608 00:34:08,710 --> 00:34:08,720 column is changed so this is the benefit 1609 00:34:08,720 --> 00:34:10,780 column is changed so this is the benefit of using an alias we can give 1610 00:34:10,780 --> 00:34:10,790 of using an alias we can give 1611 00:34:10,790 --> 00:34:13,210 of using an alias we can give descriptive names to the columns and the 1612 00:34:13,210 --> 00:34:13,220 descriptive names to the columns and the 1613 00:34:13,220 --> 00:34:15,580 descriptive names to the columns and the result set now if you don't have a space 1614 00:34:15,580 --> 00:34:15,590 result set now if you don't have a space 1615 00:34:15,590 --> 00:34:17,830 result set now if you don't have a space in the column name you need to surround 1616 00:34:17,830 --> 00:34:17,840 in the column name you need to surround 1617 00:34:17,840 --> 00:34:21,250 in the column name you need to surround it with quotes either single or double 1618 00:34:21,250 --> 00:34:21,260 it with quotes either single or double 1619 00:34:21,260 --> 00:34:24,099 it with quotes either single or double quotes so you put quotes here and then 1620 00:34:24,099 --> 00:34:24,109 quotes so you put quotes here and then 1621 00:34:24,109 --> 00:34:27,159 quotes so you put quotes here and then we can add a space in between these two 1622 00:34:27,159 --> 00:34:27,169 we can add a space in between these two 1623 00:34:27,169 --> 00:34:29,200 we can add a space in between these two words let's execute the query one more 1624 00:34:29,200 --> 00:34:29,210 words let's execute the query one more 1625 00:34:29,210 --> 00:34:33,340 words let's execute the query one more time now we've got discount factor so 1626 00:34:33,340 --> 00:34:33,350 time now we've got discount factor so 1627 00:34:33,350 --> 00:34:34,780 time now we've got discount factor so let's quickly recap everything you learn 1628 00:34:34,780 --> 00:34:34,790 let's quickly recap everything you learn 1629 00:34:34,790 --> 00:34:37,389 let's quickly recap everything you learn about the Select Clause we can use an 1630 00:34:37,389 --> 00:34:37,399 about the Select Clause we can use an 1631 00:34:37,399 --> 00:34:40,119 about the Select Clause we can use an asterisk to return all the columns or we 1632 00:34:40,119 --> 00:34:40,129 asterisk to return all the columns or we 1633 00:34:40,129 --> 00:34:42,760 asterisk to return all the columns or we can explicitly specify the columns that 1634 00:34:42,760 --> 00:34:42,770 can explicitly specify the columns that 1635 00:34:42,770 --> 00:34:44,770 can explicitly specify the columns that you want to return we can also use 1636 00:34:44,770 --> 00:34:44,780 you want to return we can also use 1637 00:34:44,780 --> 00:34:46,659 you want to return we can also use arrays math expressions here and 1638 00:34:46,659 --> 00:34:46,669 arrays math expressions here and 1639 00:34:46,669 --> 00:34:49,210 arrays math expressions here and optionally we can give an alias to each 1640 00:34:49,210 --> 00:34:49,220 optionally we can give an alias to each 1641 00:34:49,220 --> 00:34:50,020 optionally we can give an alias to each column 1642 00:34:50,020 --> 00:34:50,030 column 1643 00:34:50,030 --> 00:34:52,090 column the results set now there is one more 1644 00:34:52,090 --> 00:34:52,100 the results set now there is one more 1645 00:34:52,100 --> 00:34:53,830 the results set now there is one more thing you need to know about the select 1646 00:34:53,830 --> 00:34:53,840 thing you need to know about the select 1647 00:34:53,840 --> 00:34:55,810 thing you need to know about the select clause so let's delete this query and 1648 00:34:55,810 --> 00:34:55,820 clause so let's delete this query and 1649 00:34:55,820 --> 00:35:00,370 clause so let's delete this query and select the state column from the 1650 00:35:00,370 --> 00:35:00,380 select the state column from the 1651 00:35:00,380 --> 00:35:01,840 select the state column from the customers table 1652 00:35:01,840 --> 00:35:01,850 customers table 1653 00:35:01,850 --> 00:35:04,450 customers table take a look these are the states in 1654 00:35:04,450 --> 00:35:04,460 take a look these are the states in 1655 00:35:04,460 --> 00:35:06,970 take a look these are the states in which our customers are located now 1656 00:35:06,970 --> 00:35:06,980 which our customers are located now 1657 00:35:06,980 --> 00:35:08,620 which our customers are located now currently in the sample data we don't 1658 00:35:08,620 --> 00:35:08,630 currently in the sample data we don't 1659 00:35:08,630 --> 00:35:10,840 currently in the sample data we don't have any duplicates in other words we 1660 00:35:10,840 --> 00:35:10,850 have any duplicates in other words we 1661 00:35:10,850 --> 00:35:12,820 have any duplicates in other words we don't have multiple customers in any of 1662 00:35:12,820 --> 00:35:12,830 don't have multiple customers in any of 1663 00:35:12,830 --> 00:35:15,010 don't have multiple customers in any of these states but for this demo I want to 1664 00:35:15,010 --> 00:35:15,020 these states but for this demo I want to 1665 00:35:15,020 --> 00:35:17,110 these states but for this demo I want to change the state of the first customer 1666 00:35:17,110 --> 00:35:17,120 change the state of the first customer 1667 00:35:17,120 --> 00:35:19,450 change the state of the first customer to Virginia so we end up with duplicates 1668 00:35:19,450 --> 00:35:19,460 to Virginia so we end up with duplicates 1669 00:35:19,460 --> 00:35:22,660 to Virginia so we end up with duplicates in the result set so let's open up the 1670 00:35:22,660 --> 00:35:22,670 in the result set so let's open up the 1671 00:35:22,670 --> 00:35:25,450 in the result set so let's open up the navigator panel here's our customers 1672 00:35:25,450 --> 00:35:25,460 navigator panel here's our customers 1673 00:35:25,460 --> 00:35:30,180 navigator panel here's our customers table let's look at all the data and 1674 00:35:30,180 --> 00:35:30,190 1675 00:35:30,190 --> 00:35:32,940 here's our first customer as you can see 1676 00:35:32,940 --> 00:35:32,950 here's our first customer as you can see 1677 00:35:32,950 --> 00:35:35,310 here's our first customer as you can see it's located in the state of 1678 00:35:35,310 --> 00:35:35,320 it's located in the state of 1679 00:35:35,320 --> 00:35:37,810 it's located in the state of Massachusetts now I want to change this 1680 00:35:37,810 --> 00:35:37,820 Massachusetts now I want to change this 1681 00:35:37,820 --> 00:35:41,920 Massachusetts now I want to change this to Virginia so double-click VA for 1682 00:35:41,920 --> 00:35:41,930 to Virginia so double-click VA for 1683 00:35:41,930 --> 00:35:45,520 to Virginia so double-click VA for Virginia enter done now on the bottom 1684 00:35:45,520 --> 00:35:45,530 Virginia enter done now on the bottom 1685 00:35:45,530 --> 00:35:46,930 Virginia enter done now on the bottom right corner of the screen you should 1686 00:35:46,930 --> 00:35:46,940 right corner of the screen you should 1687 00:35:46,940 --> 00:35:50,110 right corner of the screen you should see two buttons apply and revert 1688 00:35:50,110 --> 00:35:50,120 see two buttons apply and revert 1689 00:35:50,120 --> 00:35:51,940 see two buttons apply and revert unfortunately I cannot show you these 1690 00:35:51,940 --> 00:35:51,950 unfortunately I cannot show you these 1691 00:35:51,950 --> 00:35:53,620 unfortunately I cannot show you these buttons because the recording window is 1692 00:35:53,620 --> 00:35:53,630 buttons because the recording window is 1693 00:35:53,630 --> 00:35:56,650 buttons because the recording window is a bit smaller and MySQL workbench but 1694 00:35:56,650 --> 00:35:56,660 a bit smaller and MySQL workbench but 1695 00:35:56,660 --> 00:35:58,840 a bit smaller and MySQL workbench but look down the bottom in the bottom right 1696 00:35:58,840 --> 00:35:58,850 look down the bottom in the bottom right 1697 00:35:58,850 --> 00:36:02,500 look down the bottom in the bottom right corner click on apply you're going to 1698 00:36:02,500 --> 00:36:02,510 corner click on apply you're going to 1699 00:36:02,510 --> 00:36:04,300 corner click on apply you're going to see a dialog box like this asking you to 1700 00:36:04,300 --> 00:36:04,310 see a dialog box like this asking you to 1701 00:36:04,310 --> 00:36:06,670 see a dialog box like this asking you to review the changes so go ahead and click 1702 00:36:06,670 --> 00:36:06,680 review the changes so go ahead and click 1703 00:36:06,680 --> 00:36:09,850 review the changes so go ahead and click the apply button one more time all right 1704 00:36:09,850 --> 00:36:09,860 the apply button one more time all right 1705 00:36:09,860 --> 00:36:12,700 the apply button one more time all right beautiful now let's go back to our first 1706 00:36:12,700 --> 00:36:12,710 beautiful now let's go back to our first 1707 00:36:12,710 --> 00:36:15,130 beautiful now let's go back to our first query window and execute this query one 1708 00:36:15,130 --> 00:36:15,140 query window and execute this query one 1709 00:36:15,140 --> 00:36:18,910 query window and execute this query one more time as you can see the first two 1710 00:36:18,910 --> 00:36:18,920 more time as you can see the first two 1711 00:36:18,920 --> 00:36:22,180 more time as you can see the first two customers are located in Virginia what 1712 00:36:22,180 --> 00:36:22,190 customers are located in Virginia what 1713 00:36:22,190 --> 00:36:23,950 customers are located in Virginia what if you want to get the unique list of 1714 00:36:23,950 --> 00:36:23,960 if you want to get the unique list of 1715 00:36:23,960 --> 00:36:26,470 if you want to get the unique list of states and the result set that's when we 1716 00:36:26,470 --> 00:36:26,480 states and the result set that's when we 1717 00:36:26,480 --> 00:36:29,970 states and the result set that's when we use the distinct keyword so select 1718 00:36:29,970 --> 00:36:29,980 use the distinct keyword so select 1719 00:36:29,980 --> 00:36:33,550 use the distinct keyword so select distinct state with this query we'll 1720 00:36:33,550 --> 00:36:33,560 distinct state with this query we'll 1721 00:36:33,560 --> 00:36:35,890 distinct state with this query we'll retrieve the unique list of states from 1722 00:36:35,890 --> 00:36:35,900 retrieve the unique list of states from 1723 00:36:35,900 --> 00:36:38,170 retrieve the unique list of states from the customers table so with a distinct 1724 00:36:38,170 --> 00:36:38,180 the customers table so with a distinct 1725 00:36:38,180 --> 00:36:40,000 the customers table so with a distinct keyword we can remove the duplicates 1726 00:36:40,000 --> 00:36:40,010 keyword we can remove the duplicates 1727 00:36:40,010 --> 00:36:42,270 keyword we can remove the duplicates let's execute the query one more time 1728 00:36:42,270 --> 00:36:42,280 let's execute the query one more time 1729 00:36:42,280 --> 00:36:45,100 let's execute the query one more time now we can see Virginia is not 1730 00:36:45,100 --> 00:36:45,110 now we can see Virginia is not 1731 00:36:45,110 --> 00:36:46,840 now we can see Virginia is not duplicated 1732 00:36:46,840 --> 00:36:46,850 duplicated 1733 00:36:46,850 --> 00:36:49,820 duplicated you 1734 00:36:49,820 --> 00:36:49,830 1735 00:36:49,830 --> 00:36:52,050 all right here's an exercise for you I 1736 00:36:52,050 --> 00:36:52,060 all right here's an exercise for you I 1737 00:36:52,060 --> 00:36:54,480 all right here's an exercise for you I want you to write a sequel query to 1738 00:36:54,480 --> 00:36:54,490 want you to write a sequel query to 1739 00:36:54,490 --> 00:36:55,980 want you to write a sequel query to return all the products in our database 1740 00:36:55,980 --> 00:36:55,990 return all the products in our database 1741 00:36:55,990 --> 00:36:57,810 return all the products in our database in the results set 1742 00:36:57,810 --> 00:36:57,820 in the results set 1743 00:36:57,820 --> 00:37:01,140 in the results set I want to see three columns named unit 1744 00:37:01,140 --> 00:37:01,150 I want to see three columns named unit 1745 00:37:01,150 --> 00:37:04,080 I want to see three columns named unit price and a new column called new price 1746 00:37:04,080 --> 00:37:04,090 price and a new column called new price 1747 00:37:04,090 --> 00:37:07,110 price and a new column called new price which is based on this expression unit 1748 00:37:07,110 --> 00:37:07,120 which is based on this expression unit 1749 00:37:07,120 --> 00:37:10,050 which is based on this expression unit price times 1.1 so let's say we want to 1750 00:37:10,050 --> 00:37:10,060 price times 1.1 so let's say we want to 1751 00:37:10,060 --> 00:37:12,030 price times 1.1 so let's say we want to increase the price of each product by 1752 00:37:12,030 --> 00:37:12,040 increase the price of each product by 1753 00:37:12,040 --> 00:37:14,820 increase the price of each product by 10% with this query we want to get all 1754 00:37:14,820 --> 00:37:14,830 10% with this query we want to get all 1755 00:37:14,830 --> 00:37:17,070 10% with this query we want to get all the products the original price and 1756 00:37:17,070 --> 00:37:17,080 the products the original price and 1757 00:37:17,080 --> 00:37:19,530 the products the original price and their new price so pause the video and 1758 00:37:19,530 --> 00:37:19,540 their new price so pause the video and 1759 00:37:19,540 --> 00:37:21,210 their new price so pause the video and spend one or two minutes on this 1760 00:37:21,210 --> 00:37:21,220 spend one or two minutes on this 1761 00:37:21,220 --> 00:37:23,070 spend one or two minutes on this exercise when you're done come back see 1762 00:37:23,070 --> 00:37:23,080 exercise when you're done come back see 1763 00:37:23,080 --> 00:37:27,620 exercise when you're done come back see my solution 1764 00:37:27,620 --> 00:37:27,630 1765 00:37:27,630 --> 00:37:30,480 all right this is pretty easy so we 1766 00:37:30,480 --> 00:37:30,490 all right this is pretty easy so we 1767 00:37:30,490 --> 00:37:33,000 all right this is pretty easy so we start with select now what columns do we 1768 00:37:33,000 --> 00:37:33,010 start with select now what columns do we 1769 00:37:33,010 --> 00:37:36,480 start with select now what columns do we want to select name unit underline price 1770 00:37:36,480 --> 00:37:36,490 want to select name unit underline price 1771 00:37:36,490 --> 00:37:39,480 want to select name unit underline price and then here we're gonna use an 1772 00:37:39,480 --> 00:37:39,490 and then here we're gonna use an 1773 00:37:39,490 --> 00:37:42,060 and then here we're gonna use an arithmetic expression to calculate a new 1774 00:37:42,060 --> 00:37:42,070 arithmetic expression to calculate a new 1775 00:37:42,070 --> 00:37:45,870 arithmetic expression to calculate a new price so we type out unit price times 1776 00:37:45,870 --> 00:37:45,880 price so we type out unit price times 1777 00:37:45,880 --> 00:37:48,570 price so we type out unit price times one point one I didn't give it an alias 1778 00:37:48,570 --> 00:37:48,580 one point one I didn't give it an alias 1779 00:37:48,580 --> 00:37:51,540 one point one I didn't give it an alias so as new underlined price or we could 1780 00:37:51,540 --> 00:37:51,550 so as new underlined price or we could 1781 00:37:51,550 --> 00:37:53,640 so as new underlined price or we could put this in quotes and put a space with 1782 00:37:53,640 --> 00:37:53,650 put this in quotes and put a space with 1783 00:37:53,650 --> 00:37:56,040 put this in quotes and put a space with a new and price now where do we want to 1784 00:37:56,040 --> 00:37:56,050 a new and price now where do we want to 1785 00:37:56,050 --> 00:37:58,080 a new and price now where do we want to select this columns from from the 1786 00:37:58,080 --> 00:37:58,090 select this columns from from the 1787 00:37:58,090 --> 00:38:01,500 select this columns from from the products table so from products note 1788 00:38:01,500 --> 00:38:01,510 products table so from products note 1789 00:38:01,510 --> 00:38:03,480 products table so from products note that I've used uppercase characters for 1790 00:38:03,480 --> 00:38:03,490 that I've used uppercase characters for 1791 00:38:03,490 --> 00:38:05,730 that I've used uppercase characters for all the sequel keywords and lowercase 1792 00:38:05,730 --> 00:38:05,740 all the sequel keywords and lowercase 1793 00:38:05,740 --> 00:38:08,250 all the sequel keywords and lowercase characters for everything else so let's 1794 00:38:08,250 --> 00:38:08,260 characters for everything else so let's 1795 00:38:08,260 --> 00:38:10,860 characters for everything else so let's go ahead and execute this query this is 1796 00:38:10,860 --> 00:38:10,870 go ahead and execute this query this is 1797 00:38:10,870 --> 00:38:13,440 go ahead and execute this query this is what we get so these are all the 1798 00:38:13,440 --> 00:38:13,450 what we get so these are all the 1799 00:38:13,450 --> 00:38:15,750 what we get so these are all the products you can see their original 1800 00:38:15,750 --> 00:38:15,760 products you can see their original 1801 00:38:15,760 --> 00:38:17,670 products you can see their original price as well as the new price which is 1802 00:38:17,670 --> 00:38:17,680 price as well as the new price which is 1803 00:38:17,680 --> 00:38:25,860 price as well as the new price which is 10% more expensive in this tutorial 1804 00:38:25,860 --> 00:38:25,870 10% more expensive in this tutorial 1805 00:38:25,870 --> 00:38:28,080 10% more expensive in this tutorial we're gonna look at the where clause in 1806 00:38:28,080 --> 00:38:28,090 we're gonna look at the where clause in 1807 00:38:28,090 --> 00:38:30,390 we're gonna look at the where clause in sequel so earlier I told you that we use 1808 00:38:30,390 --> 00:38:30,400 sequel so earlier I told you that we use 1809 00:38:30,400 --> 00:38:33,180 sequel so earlier I told you that we use the where clause to filter data for 1810 00:38:33,180 --> 00:38:33,190 the where clause to filter data for 1811 00:38:33,190 --> 00:38:34,740 the where clause to filter data for example let's say we only want to get 1812 00:38:34,740 --> 00:38:34,750 example let's say we only want to get 1813 00:38:34,750 --> 00:38:37,110 example let's say we only want to get the customers with points greater than 1814 00:38:37,110 --> 00:38:37,120 the customers with points greater than 1815 00:38:37,120 --> 00:38:39,780 the customers with points greater than 3000 so here in the where clause we can 1816 00:38:39,780 --> 00:38:39,790 3000 so here in the where clause we can 1817 00:38:39,790 --> 00:38:42,270 3000 so here in the where clause we can type out a condition like this points 1818 00:38:42,270 --> 00:38:42,280 type out a condition like this points 1819 00:38:42,280 --> 00:38:45,990 type out a condition like this points greater than 3000 when we execute this 1820 00:38:45,990 --> 00:38:46,000 greater than 3000 when we execute this 1821 00:38:46,000 --> 00:38:48,480 greater than 3000 when we execute this query the query execution engine in 1822 00:38:48,480 --> 00:38:48,490 query the query execution engine in 1823 00:38:48,490 --> 00:38:51,240 query the query execution engine in MySQL is going to iterate over all the 1824 00:38:51,240 --> 00:38:51,250 MySQL is going to iterate over all the 1825 00:38:51,250 --> 00:38:53,670 MySQL is going to iterate over all the customers in the customers table for 1826 00:38:53,670 --> 00:38:53,680 customers in the customers table for 1827 00:38:53,680 --> 00:38:55,740 customers in the customers table for each customer is going to evaluate this 1828 00:38:55,740 --> 00:38:55,750 each customer is going to evaluate this 1829 00:38:55,750 --> 00:38:58,230 each customer is going to evaluate this condition if this condition is true it 1830 00:38:58,230 --> 00:38:58,240 condition if this condition is true it 1831 00:38:58,240 --> 00:39:00,330 condition if this condition is true it will return that customer in the result 1832 00:39:00,330 --> 00:39:00,340 will return that customer in the result 1833 00:39:00,340 --> 00:39:03,540 will return that customer in the result set so let's go ahead and execute this 1834 00:39:03,540 --> 00:39:03,550 set so let's go ahead and execute this 1835 00:39:03,550 --> 00:39:06,810 set so let's go ahead and execute this and here's the result as you can see we 1836 00:39:06,810 --> 00:39:06,820 and here's the result as you can see we 1837 00:39:06,820 --> 00:39:09,780 and here's the result as you can see we have only two customers with points 1838 00:39:09,780 --> 00:39:09,790 have only two customers with points 1839 00:39:09,790 --> 00:39:12,990 have only two customers with points greater than 3000 so this is what we 1840 00:39:12,990 --> 00:39:13,000 greater than 3000 so this is what we 1841 00:39:13,000 --> 00:39:15,210 greater than 3000 so this is what we call the greater than operator which is 1842 00:39:15,210 --> 00:39:15,220 call the greater than operator which is 1843 00:39:15,220 --> 00:39:17,100 call the greater than operator which is one of the comparison operators in 1844 00:39:17,100 --> 00:39:17,110 one of the comparison operators in 1845 00:39:17,110 --> 00:39:19,590 one of the comparison operators in sequel let me show you the complete list 1846 00:39:19,590 --> 00:39:19,600 sequel let me show you the complete list 1847 00:39:19,600 --> 00:39:23,550 sequel let me show you the complete list of comparison operators so we have 1848 00:39:23,550 --> 00:39:23,560 of comparison operators so we have 1849 00:39:23,560 --> 00:39:27,540 of comparison operators so we have greater than greater than or equal to we 1850 00:39:27,540 --> 00:39:27,550 greater than greater than or equal to we 1851 00:39:27,550 --> 00:39:30,270 greater than greater than or equal to we have less than less than or equal to 1852 00:39:30,270 --> 00:39:30,280 have less than less than or equal to 1853 00:39:30,280 --> 00:39:34,170 have less than less than or equal to here's the Equality operator and for not 1854 00:39:34,170 --> 00:39:34,180 here's the Equality operator and for not 1855 00:39:34,180 --> 00:39:35,640 here's the Equality operator and for not equality we can use an exclamation 1856 00:39:35,640 --> 00:39:35,650 equality we can use an exclamation 1857 00:39:35,650 --> 00:39:38,610 equality we can use an exclamation followed by an equal sign or something 1858 00:39:38,610 --> 00:39:38,620 followed by an equal sign or something 1859 00:39:38,620 --> 00:39:41,030 followed by an equal sign or something like this so both these are 1860 00:39:41,030 --> 00:39:41,040 like this so both these are 1861 00:39:41,040 --> 00:39:43,160 like this so both these are not equal operators let me show you a 1862 00:39:43,160 --> 00:39:43,170 not equal operators let me show you a 1863 00:39:43,170 --> 00:39:45,770 not equal operators let me show you a few examples of these operators so I'm 1864 00:39:45,770 --> 00:39:45,780 few examples of these operators so I'm 1865 00:39:45,780 --> 00:39:48,170 few examples of these operators so I'm gonna delete all this and bring back the 1866 00:39:48,170 --> 00:39:48,180 gonna delete all this and bring back the 1867 00:39:48,180 --> 00:39:50,240 gonna delete all this and bring back the previous query let's say we want to get 1868 00:39:50,240 --> 00:39:50,250 previous query let's say we want to get 1869 00:39:50,250 --> 00:39:52,130 previous query let's say we want to get only the customers in the state of 1870 00:39:52,130 --> 00:39:52,140 only the customers in the state of 1871 00:39:52,140 --> 00:39:54,740 only the customers in the state of Virginia so we can change our condition 1872 00:39:54,740 --> 00:39:54,750 Virginia so we can change our condition 1873 00:39:54,750 --> 00:39:56,950 Virginia so we can change our condition to something like this where state 1874 00:39:56,950 --> 00:39:56,960 to something like this where state 1875 00:39:56,960 --> 00:40:00,920 to something like this where state equals Virginia note that up with 1876 00:40:00,920 --> 00:40:00,930 equals Virginia note that up with 1877 00:40:00,930 --> 00:40:03,320 equals Virginia note that up with Virginia in quotes because this is what 1878 00:40:03,320 --> 00:40:03,330 Virginia in quotes because this is what 1879 00:40:03,330 --> 00:40:05,750 Virginia in quotes because this is what we call a string a string is a sequence 1880 00:40:05,750 --> 00:40:05,760 we call a string a string is a sequence 1881 00:40:05,760 --> 00:40:08,000 we call a string a string is a sequence of characters so whenever you're dealing 1882 00:40:08,000 --> 00:40:08,010 of characters so whenever you're dealing 1883 00:40:08,010 --> 00:40:09,830 of characters so whenever you're dealing with a sequence of characters or 1884 00:40:09,830 --> 00:40:09,840 with a sequence of characters or 1885 00:40:09,840 --> 00:40:12,140 with a sequence of characters or basically textual data you need to 1886 00:40:12,140 --> 00:40:12,150 basically textual data you need to 1887 00:40:12,150 --> 00:40:14,420 basically textual data you need to enclose your values with either single 1888 00:40:14,420 --> 00:40:14,430 enclose your values with either single 1889 00:40:14,430 --> 00:40:17,540 enclose your values with either single or double quotes but quite often by 1890 00:40:17,540 --> 00:40:17,550 or double quotes but quite often by 1891 00:40:17,550 --> 00:40:20,780 or double quotes but quite often by convention we use single quotes so let's 1892 00:40:20,780 --> 00:40:20,790 convention we use single quotes so let's 1893 00:40:20,790 --> 00:40:24,290 convention we use single quotes so let's execute this query and here's the result 1894 00:40:24,290 --> 00:40:24,300 execute this query and here's the result 1895 00:40:24,300 --> 00:40:26,330 execute this query and here's the result you can see we only have these two 1896 00:40:26,330 --> 00:40:26,340 you can see we only have these two 1897 00:40:26,340 --> 00:40:28,940 you can see we only have these two customers with ID one and two who are 1898 00:40:28,940 --> 00:40:28,950 customers with ID one and two who are 1899 00:40:28,950 --> 00:40:31,970 customers with ID one and two who are located in Virginia and it doesn't 1900 00:40:31,970 --> 00:40:31,980 located in Virginia and it doesn't 1901 00:40:31,980 --> 00:40:34,120 located in Virginia and it doesn't matter if we use uppercase or lowercase 1902 00:40:34,120 --> 00:40:34,130 matter if we use uppercase or lowercase 1903 00:40:34,130 --> 00:40:36,470 matter if we use uppercase or lowercase characters so if we type out 1904 00:40:36,470 --> 00:40:36,480 characters so if we type out 1905 00:40:36,480 --> 00:40:39,680 characters so if we type out VA in lowercase and execute the query we 1906 00:40:39,680 --> 00:40:39,690 VA in lowercase and execute the query we 1907 00:40:39,690 --> 00:40:42,290 VA in lowercase and execute the query we get the exact same result now what if 1908 00:40:42,290 --> 00:40:42,300 get the exact same result now what if 1909 00:40:42,300 --> 00:40:43,760 get the exact same result now what if you want to get all the customers 1910 00:40:43,760 --> 00:40:43,770 you want to get all the customers 1911 00:40:43,770 --> 00:40:46,550 you want to get all the customers outside of the state of Virginia we can 1912 00:40:46,550 --> 00:40:46,560 outside of the state of Virginia we can 1913 00:40:46,560 --> 00:40:49,310 outside of the state of Virginia we can use the not equal operator so we can 1914 00:40:49,310 --> 00:40:49,320 use the not equal operator so we can 1915 00:40:49,320 --> 00:40:52,060 use the not equal operator so we can either prefix this with an exclamation 1916 00:40:52,060 --> 00:40:52,070 either prefix this with an exclamation 1917 00:40:52,070 --> 00:40:57,620 either prefix this with an exclamation or use this other notation either way we 1918 00:40:57,620 --> 00:40:57,630 or use this other notation either way we 1919 00:40:57,630 --> 00:41:00,260 or use this other notation either way we get the same result so these are the 1920 00:41:00,260 --> 00:41:00,270 get the same result so these are the 1921 00:41:00,270 --> 00:41:01,970 get the same result so these are the customers that are not located in 1922 00:41:01,970 --> 00:41:01,980 customers that are not located in 1923 00:41:01,980 --> 00:41:04,820 customers that are not located in Virginia now we can use this comparison 1924 00:41:04,820 --> 00:41:04,830 Virginia now we can use this comparison 1925 00:41:04,830 --> 00:41:07,730 Virginia now we can use this comparison operators we date values as well for 1926 00:41:07,730 --> 00:41:07,740 operators we date values as well for 1927 00:41:07,740 --> 00:41:09,230 operators we date values as well for example let's say we want to get only 1928 00:41:09,230 --> 00:41:09,240 example let's say we want to get only 1929 00:41:09,240 --> 00:41:12,670 example let's say we want to get only the customers born after January 1st 1930 00:41:12,670 --> 00:41:12,680 the customers born after January 1st 1931 00:41:12,680 --> 00:41:16,490 the customers born after January 1st 1990 so we change our condition to birth 1932 00:41:16,490 --> 00:41:16,500 1990 so we change our condition to birth 1933 00:41:16,500 --> 00:41:19,250 1990 so we change our condition to birth date greater than once again we use 1934 00:41:19,250 --> 00:41:19,260 date greater than once again we use 1935 00:41:19,260 --> 00:41:22,100 date greater than once again we use quotes for representing date values even 1936 00:41:22,100 --> 00:41:22,110 quotes for representing date values even 1937 00:41:22,110 --> 00:41:24,200 quotes for representing date values even though dates are actually not strings 1938 00:41:24,200 --> 00:41:24,210 though dates are actually not strings 1939 00:41:24,210 --> 00:41:26,000 though dates are actually not strings but in the sequel language we should 1940 00:41:26,000 --> 00:41:26,010 but in the sequel language we should 1941 00:41:26,010 --> 00:41:29,660 but in the sequel language we should enclose dates with quote so here we type 1942 00:41:29,660 --> 00:41:29,670 enclose dates with quote so here we type 1943 00:41:29,670 --> 00:41:36,320 enclose dates with quote so here we type out 1990 - 0 1 for January - 0 1 for day 1944 00:41:36,320 --> 00:41:36,330 out 1990 - 0 1 for January - 0 1 for day 1945 00:41:36,330 --> 00:41:38,510 out 1990 - 0 1 for January - 0 1 for day so this is the standard or the default 1946 00:41:38,510 --> 00:41:38,520 so this is the standard or the default 1947 00:41:38,520 --> 00:41:41,240 so this is the standard or the default format for representing dates in MySQL 1948 00:41:41,240 --> 00:41:41,250 format for representing dates in MySQL 1949 00:41:41,250 --> 00:41:43,940 format for representing dates in MySQL for digits for the year two digits for 1950 00:41:43,940 --> 00:41:43,950 for digits for the year two digits for 1951 00:41:43,950 --> 00:41:47,120 for digits for the year two digits for the month and two digits for the day so 1952 00:41:47,120 --> 00:41:47,130 the month and two digits for the day so 1953 00:41:47,130 --> 00:41:48,890 the month and two digits for the day so let's go ahead and execute this query I 1954 00:41:48,890 --> 00:41:48,900 let's go ahead and execute this query I 1955 00:41:48,900 --> 00:41:51,680 let's go ahead and execute this query I actually made a mistake here so we don't 1956 00:41:51,680 --> 00:41:51,690 actually made a mistake here so we don't 1957 00:41:51,690 --> 00:41:53,750 actually made a mistake here so we don't see the result instead we see the action 1958 00:41:53,750 --> 00:41:53,760 see the result instead we see the action 1959 00:41:53,760 --> 00:41:54,950 see the result instead we see the action output or 1960 00:41:54,950 --> 00:41:54,960 output or 1961 00:41:54,960 --> 00:41:56,900 output or the output window if you scroll to the 1962 00:41:56,900 --> 00:41:56,910 the output window if you scroll to the 1963 00:41:56,910 --> 00:41:58,819 the output window if you scroll to the bottom you can see the details of the 1964 00:41:58,819 --> 00:41:58,829 bottom you can see the details of the 1965 00:41:58,829 --> 00:42:00,769 bottom you can see the details of the error so here I used the wrong name for 1966 00:42:00,769 --> 00:42:00,779 error so here I used the wrong name for 1967 00:42:00,779 --> 00:42:03,529 error so here I used the wrong name for the column we should separate these two 1968 00:42:03,529 --> 00:42:03,539 the column we should separate these two 1969 00:42:03,539 --> 00:42:05,870 the column we should separate these two words with an underscore that is the 1970 00:42:05,870 --> 00:42:05,880 words with an underscore that is the 1971 00:42:05,880 --> 00:42:08,960 words with an underscore that is the name of our column so let's execute the 1972 00:42:08,960 --> 00:42:08,970 name of our column so let's execute the 1973 00:42:08,970 --> 00:42:11,089 name of our column so let's execute the query one more time so we only have 1974 00:42:11,089 --> 00:42:11,099 query one more time so we only have 1975 00:42:11,099 --> 00:42:13,930 query one more time so we only have three customers born after January 1st 1976 00:42:13,930 --> 00:42:13,940 three customers born after January 1st 1977 00:42:13,940 --> 00:42:16,700 three customers born after January 1st 1990 so these were examples of 1978 00:42:16,700 --> 00:42:16,710 1990 so these were examples of 1979 00:42:16,710 --> 00:42:19,490 1990 so these were examples of comparison operators in sequel in the 1980 00:42:19,490 --> 00:42:19,500 comparison operators in sequel in the 1981 00:42:19,500 --> 00:42:21,230 comparison operators in sequel in the next tutorial I'm gonna show you how to 1982 00:42:21,230 --> 00:42:21,240 next tutorial I'm gonna show you how to 1983 00:42:21,240 --> 00:42:23,240 next tutorial I'm gonna show you how to combine multiple conditions when 1984 00:42:23,240 --> 00:42:23,250 combine multiple conditions when 1985 00:42:23,250 --> 00:42:27,830 combine multiple conditions when filtering data 1986 00:42:27,830 --> 00:42:27,840 1987 00:42:27,840 --> 00:42:30,300 all right here's your exercise I want 1988 00:42:30,300 --> 00:42:30,310 all right here's your exercise I want 1989 00:42:30,310 --> 00:42:31,950 all right here's your exercise I want you to write a query to get the orders 1990 00:42:31,950 --> 00:42:31,960 you to write a query to get the orders 1991 00:42:31,960 --> 00:42:34,680 you to write a query to get the orders that are placed this year so look at the 1992 00:42:34,680 --> 00:42:34,690 that are placed this year so look at the 1993 00:42:34,690 --> 00:42:36,750 that are placed this year so look at the orders table see what columns do we have 1994 00:42:36,750 --> 00:42:36,760 orders table see what columns do we have 1995 00:42:36,760 --> 00:42:38,730 orders table see what columns do we have there and based on that write to query 1996 00:42:38,730 --> 00:42:38,740 there and based on that write to query 1997 00:42:38,740 --> 00:42:43,470 there and based on that write to query with a where clause 1998 00:42:43,470 --> 00:42:43,480 1999 00:42:43,480 --> 00:42:46,060 so here's the orders table in this table 2000 00:42:46,060 --> 00:42:46,070 so here's the orders table in this table 2001 00:42:46,070 --> 00:42:49,180 so here's the orders table in this table we have this column order date we can 2002 00:42:49,180 --> 00:42:49,190 we have this column order date we can 2003 00:42:49,190 --> 00:42:50,710 we have this column order date we can use this column to see the orders that 2004 00:42:50,710 --> 00:42:50,720 use this column to see the orders that 2005 00:42:50,720 --> 00:42:53,080 use this column to see the orders that are placed this year so here's our query 2006 00:42:53,080 --> 00:42:53,090 are placed this year so here's our query 2007 00:42:53,090 --> 00:42:57,820 are placed this year so here's our query select star from orders where order 2008 00:42:57,820 --> 00:42:57,830 select star from orders where order 2009 00:42:57,830 --> 00:43:01,390 select star from orders where order underline date is greater than or equal 2010 00:43:01,390 --> 00:43:01,400 underline date is greater than or equal 2011 00:43:01,400 --> 00:43:04,359 underline date is greater than or equal to January 1st 2019 assuming this is the 2012 00:43:04,359 --> 00:43:04,369 to January 1st 2019 assuming this is the 2013 00:43:04,369 --> 00:43:07,930 to January 1st 2019 assuming this is the current here so 2019 0 1 0 1 2014 00:43:07,930 --> 00:43:07,940 current here so 2019 0 1 0 1 2015 00:43:07,940 --> 00:43:10,450 current here so 2019 0 1 0 1 now since currently we are in the Year 2016 00:43:10,450 --> 00:43:10,460 now since currently we are in the Year 2017 00:43:10,460 --> 00:43:13,150 now since currently we are in the Year 2019 this query will return all the 2018 00:43:13,150 --> 00:43:13,160 2019 this query will return all the 2019 00:43:13,160 --> 00:43:15,220 2019 this query will return all the orders placed this year but next year 2020 00:43:15,220 --> 00:43:15,230 orders placed this year but next year 2021 00:43:15,230 --> 00:43:16,780 orders placed this year but next year this query is not going to give us the 2022 00:43:16,780 --> 00:43:16,790 this query is not going to give us the 2023 00:43:16,790 --> 00:43:18,700 this query is not going to give us the right result but don't worry about it 2024 00:43:18,700 --> 00:43:18,710 right result but don't worry about it 2025 00:43:18,710 --> 00:43:20,440 right result but don't worry about it later in the course I will show you how 2026 00:43:20,440 --> 00:43:20,450 later in the course I will show you how 2027 00:43:20,450 --> 00:43:22,359 later in the course I will show you how to write a query to get the orders 2028 00:43:22,359 --> 00:43:22,369 to write a query to get the orders 2029 00:43:22,369 --> 00:43:24,580 to write a query to get the orders placed in the current year so for the 2030 00:43:24,580 --> 00:43:24,590 placed in the current year so for the 2031 00:43:24,590 --> 00:43:26,859 placed in the current year so for the purpose of this exercise this is a valid 2032 00:43:26,859 --> 00:43:26,869 purpose of this exercise this is a valid 2033 00:43:26,869 --> 00:43:28,840 purpose of this exercise this is a valid solution now let's execute this query 2034 00:43:28,840 --> 00:43:28,850 solution now let's execute this query 2035 00:43:28,850 --> 00:43:32,740 solution now let's execute this query and see what we get so we have only one 2036 00:43:32,740 --> 00:43:32,750 and see what we get so we have only one 2037 00:43:32,750 --> 00:43:35,740 and see what we get so we have only one order or their ID one that is placed and 2038 00:43:35,740 --> 00:43:35,750 order or their ID one that is placed and 2039 00:43:35,750 --> 00:43:43,210 order or their ID one that is placed and the current here in this tutorial I'm 2040 00:43:43,210 --> 00:43:43,220 the current here in this tutorial I'm 2041 00:43:43,220 --> 00:43:44,349 the current here in this tutorial I'm going to show you how to combine 2042 00:43:44,349 --> 00:43:44,359 going to show you how to combine 2043 00:43:44,359 --> 00:43:46,690 going to show you how to combine multiple search conditions when 2044 00:43:46,690 --> 00:43:46,700 multiple search conditions when 2045 00:43:46,700 --> 00:43:48,910 multiple search conditions when filtering data so let's say we want to 2046 00:43:48,910 --> 00:43:48,920 filtering data so let's say we want to 2047 00:43:48,920 --> 00:43:51,010 filtering data so let's say we want to get all the customers that are born 2048 00:43:51,010 --> 00:43:51,020 get all the customers that are born 2049 00:43:51,020 --> 00:43:54,790 get all the customers that are born after January 1st 1990 who also happened 2050 00:43:54,790 --> 00:43:54,800 after January 1st 1990 who also happened 2051 00:43:54,800 --> 00:43:57,310 after January 1st 1990 who also happened to have more than a thousand points so 2052 00:43:57,310 --> 00:43:57,320 to have more than a thousand points so 2053 00:43:57,320 --> 00:44:00,640 to have more than a thousand points so this is where we use the + operator so 2054 00:44:00,640 --> 00:44:00,650 this is where we use the + operator so 2055 00:44:00,650 --> 00:44:02,950 this is where we use the + operator so we type out ant and after we type out 2056 00:44:02,950 --> 00:44:02,960 we type out ant and after we type out 2057 00:44:02,960 --> 00:44:06,010 we type out ant and after we type out another condition like points greater 2058 00:44:06,010 --> 00:44:06,020 another condition like points greater 2059 00:44:06,020 --> 00:44:09,070 another condition like points greater than a thousand now when we execute this 2060 00:44:09,070 --> 00:44:09,080 than a thousand now when we execute this 2061 00:44:09,080 --> 00:44:11,620 than a thousand now when we execute this query will only get customers who have 2062 00:44:11,620 --> 00:44:11,630 query will only get customers who have 2063 00:44:11,630 --> 00:44:14,710 query will only get customers who have both these conditions let's take a look 2064 00:44:14,710 --> 00:44:14,720 both these conditions let's take a look 2065 00:44:14,720 --> 00:44:18,250 both these conditions let's take a look so execute we only have two customers 2066 00:44:18,250 --> 00:44:18,260 so execute we only have two customers 2067 00:44:18,260 --> 00:44:20,349 so execute we only have two customers and if you look both these people are 2068 00:44:20,349 --> 00:44:20,359 and if you look both these people are 2069 00:44:20,359 --> 00:44:23,770 and if you look both these people are born after in 1990 and they have more 2070 00:44:23,770 --> 00:44:23,780 born after in 1990 and they have more 2071 00:44:23,780 --> 00:44:25,840 born after in 1990 and they have more than a thousand points so this is the 2072 00:44:25,840 --> 00:44:25,850 than a thousand points so this is the 2073 00:44:25,850 --> 00:44:28,180 than a thousand points so this is the and operator when we use this operator 2074 00:44:28,180 --> 00:44:28,190 and operator when we use this operator 2075 00:44:28,190 --> 00:44:30,730 and operator when we use this operator both these conditions should be true in 2076 00:44:30,730 --> 00:44:30,740 both these conditions should be true in 2077 00:44:30,740 --> 00:44:33,430 both these conditions should be true in contrast to the end operator we have the 2078 00:44:33,430 --> 00:44:33,440 contrast to the end operator we have the 2079 00:44:33,440 --> 00:44:36,580 contrast to the end operator we have the or operator so with or if at least one 2080 00:44:36,580 --> 00:44:36,590 or operator so with or if at least one 2081 00:44:36,590 --> 00:44:38,740 or operator so with or if at least one of these conditions is true that row 2082 00:44:38,740 --> 00:44:38,750 of these conditions is true that row 2083 00:44:38,750 --> 00:44:40,599 of these conditions is true that row will be returned in the result set 2084 00:44:40,599 --> 00:44:40,609 will be returned in the result set 2085 00:44:40,609 --> 00:44:42,670 will be returned in the result set let's take a look now we execute this 2086 00:44:42,670 --> 00:44:42,680 let's take a look now we execute this 2087 00:44:42,680 --> 00:44:45,359 let's take a look now we execute this query again instead of 2 records we have 2088 00:44:45,359 --> 00:44:45,369 query again instead of 2 records we have 2089 00:44:45,369 --> 00:44:48,640 query again instead of 2 records we have quite a few records so for example we 2090 00:44:48,640 --> 00:44:48,650 quite a few records so for example we 2091 00:44:48,650 --> 00:44:50,740 quite a few records so for example we have this person who is not born after 2092 00:44:50,740 --> 00:44:50,750 have this person who is not born after 2093 00:44:50,750 --> 00:44:53,530 have this person who is not born after 1990 but if you look at their points 2094 00:44:53,530 --> 00:44:53,540 1990 but if you look at their points 2095 00:44:53,540 --> 00:44:55,900 1990 but if you look at their points they have more than a thousand points so 2096 00:44:55,900 --> 00:44:55,910 they have more than a thousand points so 2097 00:44:55,910 --> 00:44:56,600 they have more than a thousand points so any custom 2098 00:44:56,600 --> 00:44:56,610 any custom 2099 00:44:56,610 --> 00:44:59,450 any custom records that satisfies at least one of 2100 00:44:59,450 --> 00:44:59,460 records that satisfies at least one of 2101 00:44:59,460 --> 00:45:01,580 records that satisfies at least one of these conditions will be returned now 2102 00:45:01,580 --> 00:45:01,590 these conditions will be returned now 2103 00:45:01,590 --> 00:45:03,260 these conditions will be returned now let's take this to the next level let's 2104 00:45:03,260 --> 00:45:03,270 let's take this to the next level let's 2105 00:45:03,270 --> 00:45:04,970 let's take this to the next level let's say we want to get customers who are 2106 00:45:04,970 --> 00:45:04,980 say we want to get customers who are 2107 00:45:04,980 --> 00:45:08,480 say we want to get customers who are either born after 1919 or they should 2108 00:45:08,480 --> 00:45:08,490 either born after 1919 or they should 2109 00:45:08,490 --> 00:45:11,390 either born after 1919 or they should have at least a thousand points and live 2110 00:45:11,390 --> 00:45:11,400 have at least a thousand points and live 2111 00:45:11,400 --> 00:45:14,630 have at least a thousand points and live in Virginia so this is how we do this we 2112 00:45:14,630 --> 00:45:14,640 in Virginia so this is how we do this we 2113 00:45:14,640 --> 00:45:16,910 in Virginia so this is how we do this we type out and and then we add another 2114 00:45:16,910 --> 00:45:16,920 type out and and then we add another 2115 00:45:16,920 --> 00:45:21,440 type out and and then we add another condition state equals Virginia let's 2116 00:45:21,440 --> 00:45:21,450 condition state equals Virginia let's 2117 00:45:21,450 --> 00:45:23,120 condition state equals Virginia let's execute this query and see what we get 2118 00:45:23,120 --> 00:45:23,130 execute this query and see what we get 2119 00:45:23,130 --> 00:45:25,520 execute this query and see what we get we only get four records so these are 2120 00:45:25,520 --> 00:45:25,530 we only get four records so these are 2121 00:45:25,530 --> 00:45:28,160 we only get four records so these are the customers that are born either after 2122 00:45:28,160 --> 00:45:28,170 the customers that are born either after 2123 00:45:28,170 --> 00:45:31,220 the customers that are born either after 1990 or they have more than 1,000 points 2124 00:45:31,220 --> 00:45:31,230 1990 or they have more than 1,000 points 2125 00:45:31,230 --> 00:45:34,250 1990 or they have more than 1,000 points and live in Virginia if you look at the 2126 00:45:34,250 --> 00:45:34,260 and live in Virginia if you look at the 2127 00:45:34,260 --> 00:45:36,470 and live in Virginia if you look at the first customer here this person is not 2128 00:45:36,470 --> 00:45:36,480 first customer here this person is not 2129 00:45:36,480 --> 00:45:39,260 first customer here this person is not born after 1990 but you can see that she 2130 00:45:39,260 --> 00:45:39,270 born after 1990 but you can see that she 2131 00:45:39,270 --> 00:45:41,180 born after 1990 but you can see that she lives in Virginia and she has more than 2132 00:45:41,180 --> 00:45:41,190 lives in Virginia and she has more than 2133 00:45:41,190 --> 00:45:43,280 lives in Virginia and she has more than a thousand points so the last two 2134 00:45:43,280 --> 00:45:43,290 a thousand points so the last two 2135 00:45:43,290 --> 00:45:45,800 a thousand points so the last two conditions are true for this customer 2136 00:45:45,800 --> 00:45:45,810 conditions are true for this customer 2137 00:45:45,810 --> 00:45:48,500 conditions are true for this customer now when combining multiple logical 2138 00:45:48,500 --> 00:45:48,510 now when combining multiple logical 2139 00:45:48,510 --> 00:45:50,450 now when combining multiple logical operators you need to be aware of the 2140 00:45:50,450 --> 00:45:50,460 operators you need to be aware of the 2141 00:45:50,460 --> 00:45:52,640 operators you need to be aware of the order of these operators so earlier I 2142 00:45:52,640 --> 00:45:52,650 order of these operators so earlier I 2143 00:45:52,650 --> 00:45:54,260 order of these operators so earlier I talked about the order of arithmetic 2144 00:45:54,260 --> 00:45:54,270 talked about the order of arithmetic 2145 00:45:54,270 --> 00:45:56,750 talked about the order of arithmetic operators I told you that multiplication 2146 00:45:56,750 --> 00:45:56,760 operators I told you that multiplication 2147 00:45:56,760 --> 00:45:59,750 operators I told you that multiplication have a higher order than addition and 2148 00:45:59,750 --> 00:45:59,760 have a higher order than addition and 2149 00:45:59,760 --> 00:46:02,450 have a higher order than addition and subtraction and we can use parentheses 2150 00:46:02,450 --> 00:46:02,460 subtraction and we can use parentheses 2151 00:46:02,460 --> 00:46:05,870 subtraction and we can use parentheses to override the default order we have 2152 00:46:05,870 --> 00:46:05,880 to override the default order we have 2153 00:46:05,880 --> 00:46:08,780 to override the default order we have the same concept in logical operators so 2154 00:46:08,780 --> 00:46:08,790 the same concept in logical operators so 2155 00:46:08,790 --> 00:46:11,600 the same concept in logical operators so the and operator is always evaluated 2156 00:46:11,600 --> 00:46:11,610 the and operator is always evaluated 2157 00:46:11,610 --> 00:46:14,720 the and operator is always evaluated first so when this quiz executed the 2158 00:46:14,720 --> 00:46:14,730 first so when this quiz executed the 2159 00:46:14,730 --> 00:46:17,180 first so when this quiz executed the query execution engine first evaluates 2160 00:46:17,180 --> 00:46:17,190 query execution engine first evaluates 2161 00:46:17,190 --> 00:46:19,010 query execution engine first evaluates its condition because here we're using 2162 00:46:19,010 --> 00:46:19,020 its condition because here we're using 2163 00:46:19,020 --> 00:46:21,290 its condition because here we're using an ant it doesn't matter that we typed 2164 00:46:21,290 --> 00:46:21,300 an ant it doesn't matter that we typed 2165 00:46:21,300 --> 00:46:23,390 an ant it doesn't matter that we typed out this condition after the first 2166 00:46:23,390 --> 00:46:23,400 out this condition after the first 2167 00:46:23,400 --> 00:46:25,610 out this condition after the first condition because the and operator has a 2168 00:46:25,610 --> 00:46:25,620 condition because the and operator has a 2169 00:46:25,620 --> 00:46:27,650 condition because the and operator has a higher precedence but you can always 2170 00:46:27,650 --> 00:46:27,660 higher precedence but you can always 2171 00:46:27,660 --> 00:46:29,720 higher precedence but you can always change the order using parentheses and 2172 00:46:29,720 --> 00:46:29,730 change the order using parentheses and 2173 00:46:29,730 --> 00:46:31,760 change the order using parentheses and this also makes your code cleaner and 2174 00:46:31,760 --> 00:46:31,770 this also makes your code cleaner and 2175 00:46:31,770 --> 00:46:34,880 this also makes your code cleaner and easier to understand so here we can put 2176 00:46:34,880 --> 00:46:34,890 easier to understand so here we can put 2177 00:46:34,890 --> 00:46:38,180 easier to understand so here we can put parentheses around these last two 2178 00:46:38,180 --> 00:46:38,190 parentheses around these last two 2179 00:46:38,190 --> 00:46:41,720 parentheses around these last two conditions and also we can put these on 2180 00:46:41,720 --> 00:46:41,730 conditions and also we can put these on 2181 00:46:41,730 --> 00:46:45,410 conditions and also we can put these on a new line for clarity something like 2182 00:46:45,410 --> 00:46:45,420 a new line for clarity something like 2183 00:46:45,420 --> 00:46:49,100 a new line for clarity something like this so anyone who reads this code can 2184 00:46:49,100 --> 00:46:49,110 this so anyone who reads this code can 2185 00:46:49,110 --> 00:46:51,500 this so anyone who reads this code can easy to understand what is the intent of 2186 00:46:51,500 --> 00:46:51,510 easy to understand what is the intent of 2187 00:46:51,510 --> 00:46:54,200 easy to understand what is the intent of this query now we also have another 2188 00:46:54,200 --> 00:46:54,210 this query now we also have another 2189 00:46:54,210 --> 00:46:56,990 this query now we also have another logical operator and called not and we 2190 00:46:56,990 --> 00:46:57,000 logical operator and called not and we 2191 00:46:57,000 --> 00:46:59,120 logical operator and called not and we use that to negate a condition let me 2192 00:46:59,120 --> 00:46:59,130 use that to negate a condition let me 2193 00:46:59,130 --> 00:47:01,430 use that to negate a condition let me show you so I'm going to simplify our 2194 00:47:01,430 --> 00:47:01,440 show you so I'm going to simplify our 2195 00:47:01,440 --> 00:47:04,850 show you so I'm going to simplify our word Clause let's say we're searching 2196 00:47:04,850 --> 00:47:04,860 word Clause let's say we're searching 2197 00:47:04,860 --> 00:47:07,430 word Clause let's say we're searching for customers who were born after 1990 2198 00:47:07,430 --> 00:47:07,440 for customers who were born after 1990 2199 00:47:07,440 --> 00:47:10,420 for customers who were born after 1990 or they have more than a thousand points 2200 00:47:10,420 --> 00:47:10,430 or they have more than a thousand points 2201 00:47:10,430 --> 00:47:14,500 or they have more than a thousand points if you execute this query we get these 2202 00:47:14,500 --> 00:47:14,510 if you execute this query we get these 2203 00:47:14,510 --> 00:47:17,710 if you execute this query we get these people customers with ID 1 3 5 and so on 2204 00:47:17,710 --> 00:47:17,720 people customers with ID 1 3 5 and so on 2205 00:47:17,720 --> 00:47:20,260 people customers with ID 1 3 5 and so on now we can use the not operator to 2206 00:47:20,260 --> 00:47:20,270 now we can use the not operator to 2207 00:47:20,270 --> 00:47:22,779 now we can use the not operator to negate this condition so we apply not 2208 00:47:22,779 --> 00:47:22,789 negate this condition so we apply not 2209 00:47:22,789 --> 00:47:25,289 negate this condition so we apply not here and preferably we also put 2210 00:47:25,289 --> 00:47:25,299 here and preferably we also put 2211 00:47:25,299 --> 00:47:28,660 here and preferably we also put parentheses around this condition now 2212 00:47:28,660 --> 00:47:28,670 parentheses around this condition now 2213 00:47:28,670 --> 00:47:30,490 parentheses around this condition now when we execute this query we'll see 2214 00:47:30,490 --> 00:47:30,500 when we execute this query we'll see 2215 00:47:30,500 --> 00:47:32,769 when we execute this query we'll see other customers that are not and the 2216 00:47:32,769 --> 00:47:32,779 other customers that are not and the 2217 00:47:32,779 --> 00:47:36,539 other customers that are not and the current result set let's take a look so 2218 00:47:36,539 --> 00:47:36,549 current result set let's take a look so 2219 00:47:36,549 --> 00:47:39,849 current result set let's take a look so instead of customers with IDs 1 3 5 6 2220 00:47:39,849 --> 00:47:39,859 instead of customers with IDs 1 3 5 6 2221 00:47:39,859 --> 00:47:41,769 instead of customers with IDs 1 3 5 6 and so on we get the customers with IDs 2222 00:47:41,769 --> 00:47:41,779 and so on we get the customers with IDs 2223 00:47:41,779 --> 00:47:44,980 and so on we get the customers with IDs 2 4 and 10 now technically these 2224 00:47:44,980 --> 00:47:44,990 2 4 and 10 now technically these 2225 00:47:44,990 --> 00:47:48,940 2 4 and 10 now technically these customers were born before 1990 and they 2226 00:47:48,940 --> 00:47:48,950 customers were born before 1990 and they 2227 00:47:48,950 --> 00:47:51,490 customers were born before 1990 and they have less than a thousand points so if 2228 00:47:51,490 --> 00:47:51,500 have less than a thousand points so if 2229 00:47:51,500 --> 00:47:53,589 have less than a thousand points so if you look here this first customer was 2230 00:47:53,589 --> 00:47:53,599 you look here this first customer was 2231 00:47:53,599 --> 00:47:57,130 you look here this first customer was born before 1990 and he has less than a 2232 00:47:57,130 --> 00:47:57,140 born before 1990 and he has less than a 2233 00:47:57,140 --> 00:47:59,920 born before 1990 and he has less than a thousand point how did I know that let 2234 00:47:59,920 --> 00:47:59,930 thousand point how did I know that let 2235 00:47:59,930 --> 00:48:01,299 thousand point how did I know that let me show you a trick that I learned in 2236 00:48:01,299 --> 00:48:01,309 me show you a trick that I learned in 2237 00:48:01,309 --> 00:48:04,240 me show you a trick that I learned in math whenever you have a not operator 2238 00:48:04,240 --> 00:48:04,250 math whenever you have a not operator 2239 00:48:04,250 --> 00:48:05,980 math whenever you have a not operator you can simplify your expression like 2240 00:48:05,980 --> 00:48:05,990 you can simplify your expression like 2241 00:48:05,990 --> 00:48:08,529 you can simplify your expression like this we apply the not operator to the 2242 00:48:08,529 --> 00:48:08,539 this we apply the not operator to the 2243 00:48:08,539 --> 00:48:11,470 this we apply the not operator to the first condition people who were born 2244 00:48:11,470 --> 00:48:11,480 first condition people who were born 2245 00:48:11,480 --> 00:48:14,890 first condition people who were born after 1990 how can we negate this 2246 00:48:14,890 --> 00:48:14,900 after 1990 how can we negate this 2247 00:48:14,900 --> 00:48:17,470 after 1990 how can we negate this condition well the greater than operator 2248 00:48:17,470 --> 00:48:17,480 condition well the greater than operator 2249 00:48:17,480 --> 00:48:20,680 condition well the greater than operator becomes less than or equal to that is 2250 00:48:20,680 --> 00:48:20,690 becomes less than or equal to that is 2251 00:48:20,690 --> 00:48:23,589 becomes less than or equal to that is the inverse of that condition right now 2252 00:48:23,589 --> 00:48:23,599 the inverse of that condition right now 2253 00:48:23,599 --> 00:48:27,250 the inverse of that condition right now we apply the not to or to negate the or 2254 00:48:27,250 --> 00:48:27,260 we apply the not to or to negate the or 2255 00:48:27,260 --> 00:48:31,599 we apply the not to or to negate the or what do we get we get and finally apply 2256 00:48:31,599 --> 00:48:31,609 what do we get we get and finally apply 2257 00:48:31,609 --> 00:48:33,490 what do we get we get and finally apply the not operator on the last condition 2258 00:48:33,490 --> 00:48:33,500 the not operator on the last condition 2259 00:48:33,500 --> 00:48:35,769 the not operator on the last condition people who have more than a thousand 2260 00:48:35,769 --> 00:48:35,779 people who have more than a thousand 2261 00:48:35,779 --> 00:48:38,200 people who have more than a thousand points when we negate this condition we 2262 00:48:38,200 --> 00:48:38,210 points when we negate this condition we 2263 00:48:38,210 --> 00:48:40,359 points when we negate this condition we get customers with less than or equal to 2264 00:48:40,359 --> 00:48:40,369 get customers with less than or equal to 2265 00:48:40,369 --> 00:48:43,120 get customers with less than or equal to a thousand points now we can remove the 2266 00:48:43,120 --> 00:48:43,130 a thousand points now we can remove the 2267 00:48:43,130 --> 00:48:46,510 a thousand points now we can remove the not operator to simplify this we don't 2268 00:48:46,510 --> 00:48:46,520 not operator to simplify this we don't 2269 00:48:46,520 --> 00:48:48,339 not operator to simplify this we don't need parentheses anymore because we only 2270 00:48:48,339 --> 00:48:48,349 need parentheses anymore because we only 2271 00:48:48,349 --> 00:48:50,289 need parentheses anymore because we only have two conditions that are combined 2272 00:48:50,289 --> 00:48:50,299 have two conditions that are combined 2273 00:48:50,299 --> 00:48:53,559 have two conditions that are combined with an add here is a result as you can 2274 00:48:53,559 --> 00:48:53,569 with an add here is a result as you can 2275 00:48:53,569 --> 00:48:55,390 with an add here is a result as you can see this is much easier to read and 2276 00:48:55,390 --> 00:48:55,400 see this is much easier to read and 2277 00:48:55,400 --> 00:48:57,370 see this is much easier to read and understand people who were born before 2278 00:48:57,370 --> 00:48:57,380 understand people who were born before 2279 00:48:57,380 --> 00:48:59,650 understand people who were born before this date and they have less than a 2280 00:48:59,650 --> 00:48:59,660 this date and they have less than a 2281 00:48:59,660 --> 00:49:04,370 this date and they have less than a thousand points 2282 00:49:04,370 --> 00:49:04,380 2283 00:49:04,380 --> 00:49:08,070 our taser exercise from the order items 2284 00:49:08,070 --> 00:49:08,080 our taser exercise from the order items 2285 00:49:08,080 --> 00:49:12,030 our taser exercise from the order items table get the items for order number six 2286 00:49:12,030 --> 00:49:12,040 table get the items for order number six 2287 00:49:12,040 --> 00:49:14,850 table get the items for order number six where the total price for that item is 2288 00:49:14,850 --> 00:49:14,860 where the total price for that item is 2289 00:49:14,860 --> 00:49:21,200 where the total price for that item is greater than 30 2290 00:49:21,200 --> 00:49:21,210 2291 00:49:21,210 --> 00:49:23,490 all right here's the order items table 2292 00:49:23,490 --> 00:49:23,500 all right here's the order items table 2293 00:49:23,500 --> 00:49:25,529 all right here's the order items table in this table we have these columns 2294 00:49:25,529 --> 00:49:25,539 in this table we have these columns 2295 00:49:25,539 --> 00:49:26,430 in this table we have these columns order ID 2296 00:49:26,430 --> 00:49:26,440 order ID 2297 00:49:26,440 --> 00:49:29,190 order ID product ID quantity and unit price if we 2298 00:49:29,190 --> 00:49:29,200 product ID quantity and unit price if we 2299 00:49:29,200 --> 00:49:32,039 product ID quantity and unit price if we multiply the quantity by unit price we 2300 00:49:32,039 --> 00:49:32,049 multiply the quantity by unit price we 2301 00:49:32,049 --> 00:49:34,710 multiply the quantity by unit price we can get the total cost of that item and 2302 00:49:34,710 --> 00:49:34,720 can get the total cost of that item and 2303 00:49:34,720 --> 00:49:38,609 can get the total cost of that item and then we can compare it with 30 so let's 2304 00:49:38,609 --> 00:49:38,619 then we can compare it with 30 so let's 2305 00:49:38,619 --> 00:49:43,099 then we can compare it with 30 so let's go ahead and write this query select 2306 00:49:43,099 --> 00:49:43,109 go ahead and write this query select 2307 00:49:43,109 --> 00:49:48,900 go ahead and write this query select star from order items we're here we need 2308 00:49:48,900 --> 00:49:48,910 star from order items we're here we need 2309 00:49:48,910 --> 00:49:51,420 star from order items we're here we need two conditions one is for the order so 2310 00:49:51,420 --> 00:49:51,430 two conditions one is for the order so 2311 00:49:51,430 --> 00:49:55,410 two conditions one is for the order so order I'm gonna ID should be 6 and the 2312 00:49:55,410 --> 00:49:55,420 order I'm gonna ID should be 6 and the 2313 00:49:55,420 --> 00:49:57,420 order I'm gonna ID should be 6 and the second condition we want to calculate 2314 00:49:57,420 --> 00:49:57,430 second condition we want to calculate 2315 00:49:57,430 --> 00:50:00,589 second condition we want to calculate the total price so we get the unit price 2316 00:50:00,589 --> 00:50:00,599 the total price so we get the unit price 2317 00:50:00,599 --> 00:50:04,589 the total price so we get the unit price multiplied it by quantity and this value 2318 00:50:04,589 --> 00:50:04,599 multiplied it by quantity and this value 2319 00:50:04,599 --> 00:50:07,740 multiplied it by quantity and this value should be greater than 30 so as we can 2320 00:50:07,740 --> 00:50:07,750 should be greater than 30 so as we can 2321 00:50:07,750 --> 00:50:09,569 should be greater than 30 so as we can see we can use an arithmetic expression 2322 00:50:09,569 --> 00:50:09,579 see we can use an arithmetic expression 2323 00:50:09,579 --> 00:50:12,299 see we can use an arithmetic expression in a where clause it's not limited to 2324 00:50:12,299 --> 00:50:12,309 in a where clause it's not limited to 2325 00:50:12,309 --> 00:50:15,089 in a where clause it's not limited to the select clause okay now let's execute 2326 00:50:15,089 --> 00:50:15,099 the select clause okay now let's execute 2327 00:50:15,099 --> 00:50:17,240 the select clause okay now let's execute this query and see what we get 2328 00:50:17,240 --> 00:50:17,250 this query and see what we get 2329 00:50:17,250 --> 00:50:21,120 this query and see what we get we should get only one item that is for 2330 00:50:21,120 --> 00:50:21,130 we should get only one item that is for 2331 00:50:21,130 --> 00:50:23,309 we should get only one item that is for product one here the quantity is four 2332 00:50:23,309 --> 00:50:23,319 product one here the quantity is four 2333 00:50:23,319 --> 00:50:24,870 product one here the quantity is four and unit price is just over eight 2334 00:50:24,870 --> 00:50:24,880 and unit price is just over eight 2335 00:50:24,880 --> 00:50:27,029 and unit price is just over eight dollars so the total price for this item 2336 00:50:27,029 --> 00:50:27,039 dollars so the total price for this item 2337 00:50:27,039 --> 00:50:29,769 dollars so the total price for this item is greater than 30 2338 00:50:29,769 --> 00:50:29,779 is greater than 30 2339 00:50:29,779 --> 00:50:32,870 is greater than 30 hey guys maash here in case you haven't 2340 00:50:32,870 --> 00:50:32,880 hey guys maash here in case you haven't 2341 00:50:32,880 --> 00:50:35,179 hey guys maash here in case you haven't seen my website yet head over to code 2342 00:50:35,179 --> 00:50:35,189 seen my website yet head over to code 2343 00:50:35,189 --> 00:50:37,909 seen my website yet head over to code with mass comm this is my coding school 2344 00:50:37,909 --> 00:50:37,919 with mass comm this is my coding school 2345 00:50:37,919 --> 00:50:40,159 with mass comm this is my coding school where you can find plenty of courses on 2346 00:50:40,159 --> 00:50:40,169 where you can find plenty of courses on 2347 00:50:40,169 --> 00:50:41,979 where you can find plenty of courses on web and mobile application development 2348 00:50:41,979 --> 00:50:41,989 web and mobile application development 2349 00:50:41,989 --> 00:50:45,169 web and mobile application development in fact recently I published a complete 2350 00:50:45,169 --> 00:50:45,179 in fact recently I published a complete 2351 00:50:45,179 --> 00:50:47,659 in fact recently I published a complete sequel course that is about ten hours 2352 00:50:47,659 --> 00:50:47,669 sequel course that is about ten hours 2353 00:50:47,669 --> 00:50:49,579 sequel course that is about ten hours long and it teaches you everything you 2354 00:50:49,579 --> 00:50:49,589 long and it teaches you everything you 2355 00:50:49,589 --> 00:50:50,959 long and it teaches you everything you need to know from the basic to the 2356 00:50:50,959 --> 00:50:50,969 need to know from the basic to the 2357 00:50:50,969 --> 00:50:53,209 need to know from the basic to the advanced topics such as database design 2358 00:50:53,209 --> 00:50:53,219 advanced topics such as database design 2359 00:50:53,219 --> 00:50:56,079 advanced topics such as database design security writing complex queries 2360 00:50:56,079 --> 00:50:56,089 security writing complex queries 2361 00:50:56,089 --> 00:50:58,609 security writing complex queries transactions events and much much more 2362 00:50:58,609 --> 00:50:58,619 transactions events and much much more 2363 00:50:58,619 --> 00:51:01,189 transactions events and much much more these are the topics that every software 2364 00:51:01,189 --> 00:51:01,199 these are the topics that every software 2365 00:51:01,199 --> 00:51:04,189 these are the topics that every software engineer must master this YouTube course 2366 00:51:04,189 --> 00:51:04,199 engineer must master this YouTube course 2367 00:51:04,199 --> 00:51:06,199 engineer must master this YouTube course you've been watching is the first three 2368 00:51:06,199 --> 00:51:06,209 you've been watching is the first three 2369 00:51:06,209 --> 00:51:08,719 you've been watching is the first three hours of my complete sequel course that 2370 00:51:08,719 --> 00:51:08,729 hours of my complete sequel course that 2371 00:51:08,729 --> 00:51:10,999 hours of my complete sequel course that is about ten hours long so if you want 2372 00:51:10,999 --> 00:51:11,009 is about ten hours long so if you want 2373 00:51:11,009 --> 00:51:13,669 is about ten hours long so if you want to master sequel and get job ready I 2374 00:51:13,669 --> 00:51:13,679 to master sequel and get job ready I 2375 00:51:13,679 --> 00:51:15,439 to master sequel and get job ready I highly encourage you to enroll in my 2376 00:51:15,439 --> 00:51:15,449 highly encourage you to enroll in my 2377 00:51:15,449 --> 00:51:17,689 highly encourage you to enroll in my complete sequel course you can watch it 2378 00:51:17,689 --> 00:51:17,699 complete sequel course you can watch it 2379 00:51:17,699 --> 00:51:20,269 complete sequel course you can watch it anytime anywhere as many times as you 2380 00:51:20,269 --> 00:51:20,279 anytime anywhere as many times as you 2381 00:51:20,279 --> 00:51:22,579 anytime anywhere as many times as you want you can watch it online or download 2382 00:51:22,579 --> 00:51:22,589 want you can watch it online or download 2383 00:51:22,589 --> 00:51:24,349 want you can watch it online or download the videos the course comes with a 2384 00:51:24,349 --> 00:51:24,359 the videos the course comes with a 2385 00:51:24,359 --> 00:51:26,659 the videos the course comes with a 30-day money-back guarantee and a 2386 00:51:26,659 --> 00:51:26,669 30-day money-back guarantee and a 2387 00:51:26,669 --> 00:51:28,429 30-day money-back guarantee and a certificate of completion that you can 2388 00:51:28,429 --> 00:51:28,439 certificate of completion that you can 2389 00:51:28,439 --> 00:51:30,739 certificate of completion that you can add to your resume the price for this 2390 00:51:30,739 --> 00:51:30,749 add to your resume the price for this 2391 00:51:30,749 --> 00:51:32,299 add to your resume the price for this course is one hundred and forty nine 2392 00:51:32,299 --> 00:51:32,309 course is one hundred and forty nine 2393 00:51:32,309 --> 00:51:34,219 course is one hundred and forty nine dollars but the first two hundred 2394 00:51:34,219 --> 00:51:34,229 dollars but the first two hundred 2395 00:51:34,229 --> 00:51:36,409 dollars but the first two hundred students can get it for just over ten 2396 00:51:36,409 --> 00:51:36,419 students can get it for just over ten 2397 00:51:36,419 --> 00:51:38,779 students can get it for just over ten dollars so if you're interested the link 2398 00:51:38,779 --> 00:51:38,789 dollars so if you're interested the link 2399 00:51:38,789 --> 00:51:47,029 dollars so if you're interested the link is below this video in this tutorial I'm 2400 00:51:47,029 --> 00:51:47,039 is below this video in this tutorial I'm 2401 00:51:47,039 --> 00:51:48,379 is below this video in this tutorial I'm gonna show you how to use the in 2402 00:51:48,379 --> 00:51:48,389 gonna show you how to use the in 2403 00:51:48,389 --> 00:51:51,589 gonna show you how to use the in operator in sequel so as an example 2404 00:51:51,589 --> 00:51:51,599 operator in sequel so as an example 2405 00:51:51,599 --> 00:51:53,449 operator in sequel so as an example let's say we want to get the customers 2406 00:51:53,449 --> 00:51:53,459 let's say we want to get the customers 2407 00:51:53,459 --> 00:51:56,269 let's say we want to get the customers that are located in Virginia or Florida 2408 00:51:56,269 --> 00:51:56,279 that are located in Virginia or Florida 2409 00:51:56,279 --> 00:51:59,659 that are located in Virginia or Florida or Georgia one way to write this query 2410 00:51:59,659 --> 00:51:59,669 or Georgia one way to write this query 2411 00:51:59,669 --> 00:52:02,359 or Georgia one way to write this query is like this so we're state equals 2412 00:52:02,359 --> 00:52:02,369 is like this so we're state equals 2413 00:52:02,369 --> 00:52:06,709 is like this so we're state equals Virginia or state equals Georgia or 2414 00:52:06,709 --> 00:52:06,719 Virginia or state equals Georgia or 2415 00:52:06,719 --> 00:52:10,429 Virginia or state equals Georgia or state equals Florida now people who are 2416 00:52:10,429 --> 00:52:10,439 state equals Florida now people who are 2417 00:52:10,439 --> 00:52:12,019 state equals Florida now people who are new to the sequel language or 2418 00:52:12,019 --> 00:52:12,029 new to the sequel language or 2419 00:52:12,029 --> 00:52:14,569 new to the sequel language or programming in general find this 2420 00:52:14,569 --> 00:52:14,579 programming in general find this 2421 00:52:14,579 --> 00:52:16,699 programming in general find this expression a little bit strange they ask 2422 00:52:16,699 --> 00:52:16,709 expression a little bit strange they ask 2423 00:52:16,709 --> 00:52:18,379 expression a little bit strange they ask Marsh what can't we write this 2424 00:52:18,379 --> 00:52:18,389 Marsh what can't we write this 2425 00:52:18,389 --> 00:52:21,709 Marsh what can't we write this expression like this where state equals 2426 00:52:21,709 --> 00:52:21,719 expression like this where state equals 2427 00:52:21,719 --> 00:52:25,789 expression like this where state equals Virginia or Georgia or Florida here is 2428 00:52:25,789 --> 00:52:25,799 Virginia or Georgia or Florida here is 2429 00:52:25,799 --> 00:52:28,219 Virginia or Georgia or Florida here is the reason we use the or operator to 2430 00:52:28,219 --> 00:52:28,229 the reason we use the or operator to 2431 00:52:28,229 --> 00:52:31,219 the reason we use the or operator to combine multiple conditions so here we 2432 00:52:31,219 --> 00:52:31,229 combine multiple conditions so here we 2433 00:52:31,229 --> 00:52:33,409 combine multiple conditions so here we have a condition or an expression more 2434 00:52:33,409 --> 00:52:33,419 have a condition or an expression more 2435 00:52:33,419 --> 00:52:35,419 have a condition or an expression more accurately but on the right side of this 2436 00:52:35,419 --> 00:52:35,429 accurately but on the right side of this 2437 00:52:35,429 --> 00:52:38,419 accurately but on the right side of this or operator we have a string in sequel 2438 00:52:38,419 --> 00:52:38,429 or operator we have a string in sequel 2439 00:52:38,429 --> 00:52:40,399 or operator we have a string in sequel we cannot combine a string with a 2440 00:52:40,399 --> 00:52:40,409 we cannot combine a string with a 2441 00:52:40,409 --> 00:52:43,069 we cannot combine a string with a boolean expression that produces a bully 2442 00:52:43,069 --> 00:52:43,079 boolean expression that produces a bully 2443 00:52:43,079 --> 00:52:46,099 boolean expression that produces a bully value which can be true or false so that 2444 00:52:46,099 --> 00:52:46,109 value which can be true or false so that 2445 00:52:46,109 --> 00:52:48,349 value which can be true or false so that is why we have to write or query like 2446 00:52:48,349 --> 00:52:48,359 is why we have to write or query like 2447 00:52:48,359 --> 00:52:50,630 is why we have to write or query like this so we have multiple expressions or 2448 00:52:50,630 --> 00:52:50,640 this so we have multiple expressions or 2449 00:52:50,640 --> 00:52:52,969 this so we have multiple expressions or multiple conditions and we're combining 2450 00:52:52,969 --> 00:52:52,979 multiple conditions and we're combining 2451 00:52:52,979 --> 00:52:57,109 multiple conditions and we're combining them using the or operator okay so now 2452 00:52:57,109 --> 00:52:57,119 them using the or operator okay so now 2453 00:52:57,119 --> 00:52:59,749 them using the or operator okay so now if we execute this query we get these 2454 00:52:59,749 --> 00:52:59,759 if we execute this query we get these 2455 00:52:59,759 --> 00:53:01,729 if we execute this query we get these customers here but there is a shorter 2456 00:53:01,729 --> 00:53:01,739 customers here but there is a shorter 2457 00:53:01,739 --> 00:53:03,739 customers here but there is a shorter and cleaner way to get the same result 2458 00:53:03,739 --> 00:53:03,749 and cleaner way to get the same result 2459 00:53:03,749 --> 00:53:06,229 and cleaner way to get the same result instead of combining multiple conditions 2460 00:53:06,229 --> 00:53:06,239 instead of combining multiple conditions 2461 00:53:06,239 --> 00:53:08,660 instead of combining multiple conditions using the or operator we can use the in 2462 00:53:08,660 --> 00:53:08,670 using the or operator we can use the in 2463 00:53:08,670 --> 00:53:13,699 using the or operator we can use the in operator so where state is in and then 2464 00:53:13,699 --> 00:53:13,709 operator so where state is in and then 2465 00:53:13,709 --> 00:53:15,739 operator so where state is in and then in parenthesis we add all the values 2466 00:53:15,739 --> 00:53:15,749 in parenthesis we add all the values 2467 00:53:15,749 --> 00:53:19,819 in parenthesis we add all the values like Virginia comma Florida comma 2468 00:53:19,819 --> 00:53:19,829 like Virginia comma Florida comma 2469 00:53:19,829 --> 00:53:21,739 like Virginia comma Florida comma Georgia and the order doesn't matter 2470 00:53:21,739 --> 00:53:21,749 Georgia and the order doesn't matter 2471 00:53:21,749 --> 00:53:24,620 Georgia and the order doesn't matter this query is exactly equivalent to what 2472 00:53:24,620 --> 00:53:24,630 this query is exactly equivalent to what 2473 00:53:24,630 --> 00:53:26,359 this query is exactly equivalent to what we had earlier but as you can see it's 2474 00:53:26,359 --> 00:53:26,369 we had earlier but as you can see it's 2475 00:53:26,369 --> 00:53:28,969 we had earlier but as you can see it's shorter and easier to understand so 2476 00:53:28,969 --> 00:53:28,979 shorter and easier to understand so 2477 00:53:28,979 --> 00:53:31,279 shorter and easier to understand so let's execute it look we get the exact 2478 00:53:31,279 --> 00:53:31,289 let's execute it look we get the exact 2479 00:53:31,289 --> 00:53:33,680 let's execute it look we get the exact same result now here we can also use the 2480 00:53:33,680 --> 00:53:33,690 same result now here we can also use the 2481 00:53:33,690 --> 00:53:35,809 same result now here we can also use the not operator let's say we want to get 2482 00:53:35,809 --> 00:53:35,819 not operator let's say we want to get 2483 00:53:35,819 --> 00:53:38,870 not operator let's say we want to get the customers outside of these states so 2484 00:53:38,870 --> 00:53:38,880 the customers outside of these states so 2485 00:53:38,880 --> 00:53:43,339 the customers outside of these states so we can use where state not in this list 2486 00:53:43,339 --> 00:53:43,349 we can use where state not in this list 2487 00:53:43,349 --> 00:53:46,160 we can use where state not in this list now if you execute this query we get 2488 00:53:46,160 --> 00:53:46,170 now if you execute this query we get 2489 00:53:46,170 --> 00:53:47,749 now if you execute this query we get customers who are located in Colorado 2490 00:53:47,749 --> 00:53:47,759 customers who are located in Colorado 2491 00:53:47,759 --> 00:53:50,870 customers who are located in Colorado takes us and so on so use the in 2492 00:53:50,870 --> 00:53:50,880 takes us and so on so use the in 2493 00:53:50,880 --> 00:53:52,759 takes us and so on so use the in operator when you want to compare an 2494 00:53:52,759 --> 00:53:52,769 operator when you want to compare an 2495 00:53:52,769 --> 00:53:58,890 operator when you want to compare an attribute with a list of values 2496 00:53:58,890 --> 00:53:58,900 2497 00:53:58,900 --> 00:54:01,750 now here is your exercise I want you to 2498 00:54:01,750 --> 00:54:01,760 now here is your exercise I want you to 2499 00:54:01,760 --> 00:54:04,210 now here is your exercise I want you to write a query to get the products where 2500 00:54:04,210 --> 00:54:04,220 write a query to get the products where 2501 00:54:04,220 --> 00:54:07,059 write a query to get the products where their quantity in stock equals to one of 2502 00:54:07,059 --> 00:54:07,069 their quantity in stock equals to one of 2503 00:54:07,069 --> 00:54:10,900 their quantity in stock equals to one of these values 49:38 and 72 so pause the 2504 00:54:10,900 --> 00:54:10,910 these values 49:38 and 72 so pause the 2505 00:54:10,910 --> 00:54:12,490 these values 49:38 and 72 so pause the video do this exercise and then come 2506 00:54:12,490 --> 00:54:12,500 video do this exercise and then come 2507 00:54:12,500 --> 00:54:18,450 video do this exercise and then come back continue watching 2508 00:54:18,450 --> 00:54:18,460 2509 00:54:18,460 --> 00:54:19,859 all right this is pretty easy so we do a 2510 00:54:19,859 --> 00:54:19,869 all right this is pretty easy so we do a 2511 00:54:19,869 --> 00:54:22,710 all right this is pretty easy so we do a select star to get all the columns from 2512 00:54:22,710 --> 00:54:22,720 select star to get all the columns from 2513 00:54:22,720 --> 00:54:26,120 select star to get all the columns from the products table where quantity in 2514 00:54:26,120 --> 00:54:26,130 the products table where quantity in 2515 00:54:26,130 --> 00:54:29,640 the products table where quantity in stock in we use the in operator to 2516 00:54:29,640 --> 00:54:29,650 stock in we use the in operator to 2517 00:54:29,650 --> 00:54:32,420 stock in we use the in operator to compare this attribute with these values 2518 00:54:32,420 --> 00:54:32,430 compare this attribute with these values 2519 00:54:32,430 --> 00:54:36,990 compare this attribute with these values 49:38 and 72 let's execute the query we 2520 00:54:36,990 --> 00:54:37,000 49:38 and 72 let's execute the query we 2521 00:54:37,000 --> 00:54:40,230 49:38 and 72 let's execute the query we get only two records because we don't 2522 00:54:40,230 --> 00:54:40,240 get only two records because we don't 2523 00:54:40,240 --> 00:54:42,120 get only two records because we don't have a product with quantity in stock 2524 00:54:42,120 --> 00:54:42,130 have a product with quantity in stock 2525 00:54:42,130 --> 00:54:48,690 have a product with quantity in stock equal to 72 2526 00:54:48,690 --> 00:54:48,700 2527 00:54:48,700 --> 00:54:50,890 in this tutorial we're gonna look at the 2528 00:54:50,890 --> 00:54:50,900 in this tutorial we're gonna look at the 2529 00:54:50,900 --> 00:54:54,100 in this tutorial we're gonna look at the between operator in sequa so let's say 2530 00:54:54,100 --> 00:54:54,110 between operator in sequa so let's say 2531 00:54:54,110 --> 00:54:55,810 between operator in sequa so let's say we want to get the customers who have 2532 00:54:55,810 --> 00:54:55,820 we want to get the customers who have 2533 00:54:55,820 --> 00:54:58,420 we want to get the customers who have more than a thousand and less than 3,000 2534 00:54:58,420 --> 00:54:58,430 more than a thousand and less than 3,000 2535 00:54:58,430 --> 00:55:00,640 more than a thousand and less than 3,000 points what made you write this query is 2536 00:55:00,640 --> 00:55:00,650 points what made you write this query is 2537 00:55:00,650 --> 00:55:04,090 points what made you write this query is like this where points greater than 2538 00:55:04,090 --> 00:55:04,100 like this where points greater than 2539 00:55:04,100 --> 00:55:06,370 like this where points greater than thousand well more accurately greater 2540 00:55:06,370 --> 00:55:06,380 thousand well more accurately greater 2541 00:55:06,380 --> 00:55:09,940 thousand well more accurately greater than or equal to a thousand and points 2542 00:55:09,940 --> 00:55:09,950 than or equal to a thousand and points 2543 00:55:09,950 --> 00:55:12,580 than or equal to a thousand and points less than or equal to three thousand 2544 00:55:12,580 --> 00:55:12,590 less than or equal to three thousand 2545 00:55:12,590 --> 00:55:16,270 less than or equal to three thousand when we execute this query we get how 2546 00:55:16,270 --> 00:55:16,280 when we execute this query we get how 2547 00:55:16,280 --> 00:55:18,760 when we execute this query we get how many we get four people that satisfy 2548 00:55:18,760 --> 00:55:18,770 many we get four people that satisfy 2549 00:55:18,770 --> 00:55:21,160 many we get four people that satisfy this criteria now whenever you're 2550 00:55:21,160 --> 00:55:21,170 this criteria now whenever you're 2551 00:55:21,170 --> 00:55:23,260 this criteria now whenever you're comparing an attribute with a range of 2552 00:55:23,260 --> 00:55:23,270 comparing an attribute with a range of 2553 00:55:23,270 --> 00:55:25,750 comparing an attribute with a range of values you can use the between operator 2554 00:55:25,750 --> 00:55:25,760 values you can use the between operator 2555 00:55:25,760 --> 00:55:27,550 values you can use the between operator and this makes your code shorter and 2556 00:55:27,550 --> 00:55:27,560 and this makes your code shorter and 2557 00:55:27,560 --> 00:55:29,530 and this makes your code shorter and cleaner so we can rewrite this 2558 00:55:29,530 --> 00:55:29,540 cleaner so we can rewrite this 2559 00:55:29,540 --> 00:55:32,080 cleaner so we can rewrite this expression like this where points 2560 00:55:32,080 --> 00:55:32,090 expression like this where points 2561 00:55:32,090 --> 00:55:36,310 expression like this where points between thousand and three thousand this 2562 00:55:36,310 --> 00:55:36,320 between thousand and three thousand this 2563 00:55:36,320 --> 00:55:38,140 between thousand and three thousand this is exactly equivalent to what we had 2564 00:55:38,140 --> 00:55:38,150 is exactly equivalent to what we had 2565 00:55:38,150 --> 00:55:40,930 is exactly equivalent to what we had before so these range values are also 2566 00:55:40,930 --> 00:55:40,940 before so these range values are also 2567 00:55:40,940 --> 00:55:43,840 before so these range values are also inclusive that means point is going to 2568 00:55:43,840 --> 00:55:43,850 inclusive that means point is going to 2569 00:55:43,850 --> 00:55:45,820 inclusive that means point is going to be greater than or equal to a thousand 2570 00:55:45,820 --> 00:55:45,830 be greater than or equal to a thousand 2571 00:55:45,830 --> 00:55:48,460 be greater than or equal to a thousand or less than or equal to three thousand 2572 00:55:48,460 --> 00:55:48,470 or less than or equal to three thousand 2573 00:55:48,470 --> 00:55:50,890 or less than or equal to three thousand let's execute the query we get the exact 2574 00:55:50,890 --> 00:55:50,900 let's execute the query we get the exact 2575 00:55:50,900 --> 00:55:55,480 let's execute the query we get the exact same result 2576 00:55:55,480 --> 00:55:55,490 2577 00:55:55,490 --> 00:55:58,190 alright now as an exercise I wanted to 2578 00:55:58,190 --> 00:55:58,200 alright now as an exercise I wanted to 2579 00:55:58,200 --> 00:55:59,990 alright now as an exercise I wanted to write a query to get the customers that 2580 00:55:59,990 --> 00:56:00,000 write a query to get the customers that 2581 00:56:00,000 --> 00:56:03,440 write a query to get the customers that are born between January 1st 1990 and 2582 00:56:03,440 --> 00:56:03,450 are born between January 1st 1990 and 2583 00:56:03,450 --> 00:56:07,290 are born between January 1st 1990 and January 1st 2000 2584 00:56:07,290 --> 00:56:07,300 2585 00:56:07,300 --> 00:56:10,569 you 2586 00:56:10,569 --> 00:56:10,579 2587 00:56:10,579 --> 00:56:13,460 all right so we start with select star 2588 00:56:13,460 --> 00:56:13,470 all right so we start with select star 2589 00:56:13,470 --> 00:56:18,739 all right so we start with select star from customers where verse on the line 2590 00:56:18,739 --> 00:56:18,749 from customers where verse on the line 2591 00:56:18,749 --> 00:56:21,410 from customers where verse on the line date between so what matters here is 2592 00:56:21,410 --> 00:56:21,420 date between so what matters here is 2593 00:56:21,420 --> 00:56:23,539 date between so what matters here is that we can use the between operator for 2594 00:56:23,539 --> 00:56:23,549 that we can use the between operator for 2595 00:56:23,549 --> 00:56:25,489 that we can use the between operator for date values as well it's not limited to 2596 00:56:25,489 --> 00:56:25,499 date values as well it's not limited to 2597 00:56:25,499 --> 00:56:28,279 date values as well it's not limited to using numbers so we're birthdate between 2598 00:56:28,279 --> 00:56:28,289 using numbers so we're birthdate between 2599 00:56:28,289 --> 00:56:31,880 using numbers so we're birthdate between now we need to supply to date values so 2600 00:56:31,880 --> 00:56:31,890 now we need to supply to date values so 2601 00:56:31,890 --> 00:56:33,529 now we need to supply to date values so as I told you before the format for 2602 00:56:33,529 --> 00:56:33,539 as I told you before the format for 2603 00:56:33,539 --> 00:56:35,859 as I told you before the format for dates is four digits for the year so 2604 00:56:35,859 --> 00:56:35,869 dates is four digits for the year so 2605 00:56:35,869 --> 00:56:39,229 dates is four digits for the year so 1990 two digits for the months and two 2606 00:56:39,229 --> 00:56:39,239 1990 two digits for the months and two 2607 00:56:39,239 --> 00:56:42,019 1990 two digits for the months and two digits for the day so the birthday 2608 00:56:42,019 --> 00:56:42,029 digits for the day so the birthday 2609 00:56:42,029 --> 00:56:44,960 digits for the day so the birthday should be between this value and here's 2610 00:56:44,960 --> 00:56:44,970 should be between this value and here's 2611 00:56:44,970 --> 00:56:49,640 should be between this value and here's the second value 2000 0 1 and 0 1 let's 2612 00:56:49,640 --> 00:56:49,650 the second value 2000 0 1 and 0 1 let's 2613 00:56:49,650 --> 00:56:53,749 the second value 2000 0 1 and 0 1 let's execute this query we got only three 2614 00:56:53,749 --> 00:56:53,759 execute this query we got only three 2615 00:56:53,759 --> 00:57:02,120 execute this query we got only three people who match this criteria in this 2616 00:57:02,120 --> 00:57:02,130 people who match this criteria in this 2617 00:57:02,130 --> 00:57:03,289 people who match this criteria in this tutorial I'm gonna show you how to 2618 00:57:03,289 --> 00:57:03,299 tutorial I'm gonna show you how to 2619 00:57:03,299 --> 00:57:06,229 tutorial I'm gonna show you how to retrieve rows that match a specific 2620 00:57:06,229 --> 00:57:06,239 retrieve rows that match a specific 2621 00:57:06,239 --> 00:57:08,690 retrieve rows that match a specific string pattern for example let's say we 2622 00:57:08,690 --> 00:57:08,700 string pattern for example let's say we 2623 00:57:08,700 --> 00:57:10,400 string pattern for example let's say we only want to get the customers whose 2624 00:57:10,400 --> 00:57:10,410 only want to get the customers whose 2625 00:57:10,410 --> 00:57:13,759 only want to get the customers whose last name start with B so here in the 2626 00:57:13,759 --> 00:57:13,769 last name start with B so here in the 2627 00:57:13,769 --> 00:57:17,410 last name start with B so here in the where clause we type out where last name 2628 00:57:17,410 --> 00:57:17,420 where clause we type out where last name 2629 00:57:17,420 --> 00:57:19,729 where clause we type out where last name this is where we use the like operator 2630 00:57:19,729 --> 00:57:19,739 this is where we use the like operator 2631 00:57:19,739 --> 00:57:22,609 this is where we use the like operator and right after that we add a string 2632 00:57:22,609 --> 00:57:22,619 and right after that we add a string 2633 00:57:22,619 --> 00:57:25,549 and right after that we add a string pattern so you want to get the customers 2634 00:57:25,549 --> 00:57:25,559 pattern so you want to get the customers 2635 00:57:25,559 --> 00:57:28,339 pattern so you want to get the customers whose last name start with B and we have 2636 00:57:28,339 --> 00:57:28,349 whose last name start with B and we have 2637 00:57:28,349 --> 00:57:31,970 whose last name start with B and we have any number of characters after B so use 2638 00:57:31,970 --> 00:57:31,980 any number of characters after B so use 2639 00:57:31,980 --> 00:57:34,400 any number of characters after B so use the percent sign to indicate any number 2640 00:57:34,400 --> 00:57:34,410 the percent sign to indicate any number 2641 00:57:34,410 --> 00:57:36,140 the percent sign to indicate any number of characters you might have one 2642 00:57:36,140 --> 00:57:36,150 of characters you might have one 2643 00:57:36,150 --> 00:57:38,720 of characters you might have one character after B or no characters or 10 2644 00:57:38,720 --> 00:57:38,730 character after B or no characters or 10 2645 00:57:38,730 --> 00:57:41,239 character after B or no characters or 10 characters with this pattern we get all 2646 00:57:41,239 --> 00:57:41,249 characters with this pattern we get all 2647 00:57:41,249 --> 00:57:43,370 characters with this pattern we get all the customers whose last name start with 2648 00:57:43,370 --> 00:57:43,380 the customers whose last name start with 2649 00:57:43,380 --> 00:57:45,799 the customers whose last name start with B and also it doesn't matter if it's an 2650 00:57:45,799 --> 00:57:45,809 B and also it doesn't matter if it's an 2651 00:57:45,809 --> 00:57:48,739 B and also it doesn't matter if it's an uppercase or lowercase B so let's 2652 00:57:48,739 --> 00:57:48,749 uppercase or lowercase B so let's 2653 00:57:48,749 --> 00:57:51,470 uppercase or lowercase B so let's execute this query there you go so we 2654 00:57:51,470 --> 00:57:51,480 execute this query there you go so we 2655 00:57:51,480 --> 00:57:53,390 execute this query there you go so we only have three customers whose last 2656 00:57:53,390 --> 00:57:53,400 only have three customers whose last 2657 00:57:53,400 --> 00:57:56,660 only have three customers whose last name start with B as another example 2658 00:57:56,660 --> 00:57:56,670 name start with B as another example 2659 00:57:56,670 --> 00:57:58,370 name start with B as another example let's say we only want to get the 2660 00:57:58,370 --> 00:57:58,380 let's say we only want to get the 2661 00:57:58,380 --> 00:58:00,410 let's say we only want to get the customers whose last names start with 2662 00:58:00,410 --> 00:58:00,420 customers whose last names start with 2663 00:58:00,420 --> 00:58:04,039 customers whose last names start with brush so we change our pattern to brush 2664 00:58:04,039 --> 00:58:04,049 brush so we change our pattern to brush 2665 00:58:04,049 --> 00:58:07,430 brush so we change our pattern to brush percent now let's execute the query we 2666 00:58:07,430 --> 00:58:07,440 percent now let's execute the query we 2667 00:58:07,440 --> 00:58:10,460 percent now let's execute the query we only get this one customer here now this 2668 00:58:10,460 --> 00:58:10,470 only get this one customer here now this 2669 00:58:10,470 --> 00:58:12,829 only get this one customer here now this % doesn't have to be at the end of the 2670 00:58:12,829 --> 00:58:12,839 % doesn't have to be at the end of the 2671 00:58:12,839 --> 00:58:15,170 % doesn't have to be at the end of the pattern it can't be anywhere for example 2672 00:58:15,170 --> 00:58:15,180 pattern it can't be anywhere for example 2673 00:58:15,180 --> 00:58:16,279 pattern it can't be anywhere for example let's say we want to search for 2674 00:58:16,279 --> 00:58:16,289 let's say we want to search for 2675 00:58:16,289 --> 00:58:18,559 let's say we want to search for customers who have it B in their last 2676 00:58:18,559 --> 00:58:18,569 customers who have it B in their last 2677 00:58:18,569 --> 00:58:20,420 customers who have it B in their last name whether it's at the beginning in 2678 00:58:20,420 --> 00:58:20,430 name whether it's at the beginning in 2679 00:58:20,430 --> 00:58:23,029 name whether it's at the beginning in the middle or at the end so we change 2680 00:58:23,029 --> 00:58:23,039 the middle or at the end so we change 2681 00:58:23,039 --> 00:58:23,599 the middle or at the end so we change our 2682 00:58:23,599 --> 00:58:23,609 our 2683 00:58:23,609 --> 00:58:28,039 our - % b % this pattern means we can have 2684 00:58:28,039 --> 00:58:28,049 - % b % this pattern means we can have 2685 00:58:28,049 --> 00:58:30,949 - % b % this pattern means we can have any number of characters before or after 2686 00:58:30,949 --> 00:58:30,959 any number of characters before or after 2687 00:58:30,959 --> 00:58:34,640 any number of characters before or after b let's execute the query these are the 2688 00:58:34,640 --> 00:58:34,650 b let's execute the query these are the 2689 00:58:34,650 --> 00:58:37,039 b let's execute the query these are the customers who have a be somewhere and 2690 00:58:37,039 --> 00:58:37,049 customers who have a be somewhere and 2691 00:58:37,049 --> 00:58:39,140 customers who have a be somewhere and their last name it doesn't matter if 2692 00:58:39,140 --> 00:58:39,150 their last name it doesn't matter if 2693 00:58:39,150 --> 00:58:40,729 their last name it doesn't matter if being is at the beginning or in the 2694 00:58:40,729 --> 00:58:40,739 being is at the beginning or in the 2695 00:58:40,739 --> 00:58:43,249 being is at the beginning or in the middle or at the end let's look at 2696 00:58:43,249 --> 00:58:43,259 middle or at the end let's look at 2697 00:58:43,259 --> 00:58:46,339 middle or at the end let's look at another example i want to get all the 2698 00:58:46,339 --> 00:58:46,349 another example i want to get all the 2699 00:58:46,349 --> 00:58:50,390 another example i want to get all the customers whose last name and with y so 2700 00:58:50,390 --> 00:58:50,400 customers whose last name and with y so 2701 00:58:50,400 --> 00:58:52,640 customers whose last name and with y so here's the pattern we use let's execute 2702 00:58:52,640 --> 00:58:52,650 here's the pattern we use let's execute 2703 00:58:52,650 --> 00:58:55,459 here's the pattern we use let's execute this query and we have five customers 2704 00:58:55,459 --> 00:58:55,469 this query and we have five customers 2705 00:58:55,469 --> 00:58:59,479 this query and we have five customers whose last name and with a y so this is 2706 00:58:59,479 --> 00:58:59,489 whose last name and with a y so this is 2707 00:58:59,489 --> 00:59:02,620 whose last name and with a y so this is how we use the % now we also have an 2708 00:59:02,620 --> 00:59:02,630 how we use the % now we also have an 2709 00:59:02,630 --> 00:59:05,630 how we use the % now we also have an underscore and that matches a single 2710 00:59:05,630 --> 00:59:05,640 underscore and that matches a single 2711 00:59:05,640 --> 00:59:07,880 underscore and that matches a single character so with this pattern we get 2712 00:59:07,880 --> 00:59:07,890 character so with this pattern we get 2713 00:59:07,890 --> 00:59:10,910 character so with this pattern we get customers whose last name is exactly two 2714 00:59:10,910 --> 00:59:10,920 customers whose last name is exactly two 2715 00:59:10,920 --> 00:59:13,219 customers whose last name is exactly two characters long we don't care what the 2716 00:59:13,219 --> 00:59:13,229 characters long we don't care what the 2717 00:59:13,229 --> 00:59:15,109 characters long we don't care what the first character is but the second 2718 00:59:15,109 --> 00:59:15,119 first character is but the second 2719 00:59:15,119 --> 00:59:17,299 first character is but the second character should be y let's execute this 2720 00:59:17,299 --> 00:59:17,309 character should be y let's execute this 2721 00:59:17,309 --> 00:59:19,339 character should be y let's execute this query obviously we don't have any 2722 00:59:19,339 --> 00:59:19,349 query obviously we don't have any 2723 00:59:19,349 --> 00:59:21,620 query obviously we don't have any customers whose last name matches this 2724 00:59:21,620 --> 00:59:21,630 customers whose last name matches this 2725 00:59:21,630 --> 00:59:23,719 customers whose last name matches this pattern but if it changed this pattern 2726 00:59:23,719 --> 00:59:23,729 pattern but if it changed this pattern 2727 00:59:23,729 --> 00:59:27,620 pattern but if it changed this pattern to five underscores so one two three 2728 00:59:27,620 --> 00:59:27,630 to five underscores so one two three 2729 00:59:27,630 --> 00:59:31,939 to five underscores so one two three four five followed by a why we should 2730 00:59:31,939 --> 00:59:31,949 four five followed by a why we should 2731 00:59:31,949 --> 00:59:35,150 four five followed by a why we should get these customers so their last name 2732 00:59:35,150 --> 00:59:35,160 get these customers so their last name 2733 00:59:35,160 --> 00:59:37,999 get these customers so their last name is exactly six characters we don't care 2734 00:59:37,999 --> 00:59:38,009 is exactly six characters we don't care 2735 00:59:38,009 --> 00:59:39,890 is exactly six characters we don't care about the first five characters but all 2736 00:59:39,890 --> 00:59:39,900 about the first five characters but all 2737 00:59:39,900 --> 00:59:42,829 about the first five characters but all of them and wit of y now as another 2738 00:59:42,829 --> 00:59:42,839 of them and wit of y now as another 2739 00:59:42,839 --> 00:59:45,650 of them and wit of y now as another example we can replace the first 2740 00:59:45,650 --> 00:59:45,660 example we can replace the first 2741 00:59:45,660 --> 00:59:48,559 example we can replace the first underscore with b and that means we want 2742 00:59:48,559 --> 00:59:48,569 underscore with b and that means we want 2743 00:59:48,569 --> 00:59:50,089 underscore with b and that means we want to get the customers whose last name 2744 00:59:50,089 --> 00:59:50,099 to get the customers whose last name 2745 00:59:50,099 --> 00:59:53,719 to get the customers whose last name start with me and after we have exactly 2746 00:59:53,719 --> 00:59:53,729 start with me and after we have exactly 2747 00:59:53,729 --> 00:59:57,170 start with me and after we have exactly four characters followed by FY let's 2748 00:59:57,170 --> 00:59:57,180 four characters followed by FY let's 2749 00:59:57,180 --> 00:59:59,239 four characters followed by FY let's execute this query so we only have one 2750 00:59:59,239 --> 00:59:59,249 execute this query so we only have one 2751 00:59:59,249 --> 01:00:03,049 execute this query so we only have one customer that matches this pattern so 2752 01:00:03,049 --> 01:00:03,059 customer that matches this pattern so 2753 01:00:03,059 --> 01:00:05,839 customer that matches this pattern so this is how we use the like operator we 2754 01:00:05,839 --> 01:00:05,849 this is how we use the like operator we 2755 01:00:05,849 --> 01:00:07,849 this is how we use the like operator we use the percent sign to represent any 2756 01:00:07,849 --> 01:00:07,859 use the percent sign to represent any 2757 01:00:07,859 --> 01:00:12,289 use the percent sign to represent any number of characters and an underscore 2758 01:00:12,289 --> 01:00:12,299 number of characters and an underscore 2759 01:00:12,299 --> 01:00:16,519 number of characters and an underscore to present a single character now this 2760 01:00:16,519 --> 01:00:16,529 to present a single character now this 2761 01:00:16,529 --> 01:00:18,979 to present a single character now this like operator in mysql is an older 2762 01:00:18,979 --> 01:00:18,989 like operator in mysql is an older 2763 01:00:18,989 --> 01:00:21,170 like operator in mysql is an older operator but we also have a newer one 2764 01:00:21,170 --> 01:00:21,180 operator but we also have a newer one 2765 01:00:21,180 --> 01:00:23,239 operator but we also have a newer one that is more powerful and it allows us 2766 01:00:23,239 --> 01:00:23,249 that is more powerful and it allows us 2767 01:00:23,249 --> 01:00:25,400 that is more powerful and it allows us to search for any string patterns and 2768 01:00:25,400 --> 01:00:25,410 to search for any string patterns and 2769 01:00:25,410 --> 01:00:31,230 to search for any string patterns and that's what I'm going to show you next 2770 01:00:31,230 --> 01:00:31,240 2771 01:00:31,240 --> 01:00:33,220 all right here I'm gonna give you two 2772 01:00:33,220 --> 01:00:33,230 all right here I'm gonna give you two 2773 01:00:33,230 --> 01:00:36,400 all right here I'm gonna give you two exercises for the like operator first I 2774 01:00:36,400 --> 01:00:36,410 exercises for the like operator first I 2775 01:00:36,410 --> 01:00:37,960 exercises for the like operator first I want you to get the customers whose 2776 01:00:37,960 --> 01:00:37,970 want you to get the customers whose 2777 01:00:37,970 --> 01:00:42,130 want you to get the customers whose addresses contain trade or Avenue annex 2778 01:00:42,130 --> 01:00:42,140 addresses contain trade or Avenue annex 2779 01:00:42,140 --> 01:00:43,839 addresses contain trade or Avenue annex I want you to get the customers whose 2780 01:00:43,839 --> 01:00:43,849 I want you to get the customers whose 2781 01:00:43,849 --> 01:00:47,940 I want you to get the customers whose phone numbers and with nine 2782 01:00:47,940 --> 01:00:47,950 phone numbers and with nine 2783 01:00:47,950 --> 01:00:51,430 phone numbers and with nine you 2784 01:00:51,430 --> 01:00:51,440 2785 01:00:51,440 --> 01:00:53,690 alright let's get started with the first 2786 01:00:53,690 --> 01:00:53,700 alright let's get started with the first 2787 01:00:53,700 --> 01:00:57,880 alright let's get started with the first exercise so select star from customers 2788 01:00:57,880 --> 01:00:57,890 exercise so select star from customers 2789 01:00:57,890 --> 01:01:02,300 exercise so select star from customers wear a dress like like hey we want to 2790 01:01:02,300 --> 01:01:02,310 wear a dress like like hey we want to 2791 01:01:02,310 --> 01:01:04,670 wear a dress like like hey we want to use a search pattern like this you want 2792 01:01:04,670 --> 01:01:04,680 use a search pattern like this you want 2793 01:01:04,680 --> 01:01:06,830 use a search pattern like this you want to have trail but trade can be anywhere 2794 01:01:06,830 --> 01:01:06,840 to have trail but trade can be anywhere 2795 01:01:06,840 --> 01:01:09,260 to have trail but trade can be anywhere in the address so we put a percent 2796 01:01:09,260 --> 01:01:09,270 in the address so we put a percent 2797 01:01:09,270 --> 01:01:13,370 in the address so we put a percent before and after trail next we should 2798 01:01:13,370 --> 01:01:13,380 before and after trail next we should 2799 01:01:13,380 --> 01:01:15,260 before and after trail next we should use the or operator to search for 2800 01:01:15,260 --> 01:01:15,270 use the or operator to search for 2801 01:01:15,270 --> 01:01:19,970 use the or operator to search for another pattern or a dress like let me 2802 01:01:19,970 --> 01:01:19,980 another pattern or a dress like let me 2803 01:01:19,980 --> 01:01:22,520 another pattern or a dress like let me put this on a new line that is better a 2804 01:01:22,520 --> 01:01:22,530 put this on a new line that is better a 2805 01:01:22,530 --> 01:01:26,000 put this on a new line that is better a dress like once again percent Avenue 2806 01:01:26,000 --> 01:01:26,010 dress like once again percent Avenue 2807 01:01:26,010 --> 01:01:30,110 dress like once again percent Avenue percent that's it so let's execute this 2808 01:01:30,110 --> 01:01:30,120 percent that's it so let's execute this 2809 01:01:30,120 --> 01:01:32,660 percent that's it so let's execute this Quay 2810 01:01:32,660 --> 01:01:32,670 2811 01:01:32,670 --> 01:01:34,579 here's the result you should get the 2812 01:01:34,579 --> 01:01:34,589 here's the result you should get the 2813 01:01:34,589 --> 01:01:38,180 here's the result you should get the customers with IDs 2 9 and 10 if you 2814 01:01:38,180 --> 01:01:38,190 customers with IDs 2 9 and 10 if you 2815 01:01:38,190 --> 01:01:40,880 customers with IDs 2 9 and 10 if you look at their addresses all of them have 2816 01:01:40,880 --> 01:01:40,890 look at their addresses all of them have 2817 01:01:40,890 --> 01:01:44,859 look at their addresses all of them have either train or Avenue and their address 2818 01:01:44,859 --> 01:01:44,869 either train or Avenue and their address 2819 01:01:44,869 --> 01:01:47,990 either train or Avenue and their address now let's work on the second exercise we 2820 01:01:47,990 --> 01:01:48,000 now let's work on the second exercise we 2821 01:01:48,000 --> 01:01:49,400 now let's work on the second exercise we want to get the customers whose phone 2822 01:01:49,400 --> 01:01:49,410 want to get the customers whose phone 2823 01:01:49,410 --> 01:01:51,829 want to get the customers whose phone numbers and with night that is pretty 2824 01:01:51,829 --> 01:01:51,839 numbers and with night that is pretty 2825 01:01:51,839 --> 01:01:54,700 numbers and with night that is pretty easy so let me change our where clause 2826 01:01:54,700 --> 01:01:54,710 easy so let me change our where clause 2827 01:01:54,710 --> 01:01:58,039 easy so let me change our where clause where phone once again we use the like 2828 01:01:58,039 --> 01:01:58,049 where phone once again we use the like 2829 01:01:58,049 --> 01:02:00,890 where phone once again we use the like operator at a percent followed by and 2830 01:02:00,890 --> 01:02:00,900 operator at a percent followed by and 2831 01:02:00,900 --> 01:02:03,890 operator at a percent followed by and nine that's all you had to do let's 2832 01:02:03,890 --> 01:02:03,900 nine that's all you had to do let's 2833 01:02:03,900 --> 01:02:06,849 nine that's all you had to do let's execute the query so here's the result 2834 01:02:06,849 --> 01:02:06,859 execute the query so here's the result 2835 01:02:06,859 --> 01:02:10,549 execute the query so here's the result customers with IDs three and seven their 2836 01:02:10,549 --> 01:02:10,559 customers with IDs three and seven their 2837 01:02:10,559 --> 01:02:13,910 customers with IDs three and seven their phone numbers and midnight so this is 2838 01:02:13,910 --> 01:02:13,920 phone numbers and midnight so this is 2839 01:02:13,920 --> 01:02:16,160 phone numbers and midnight so this is how we use the like operator and by the 2840 01:02:16,160 --> 01:02:16,170 how we use the like operator and by the 2841 01:02:16,170 --> 01:02:18,500 how we use the like operator and by the way you can always use the not operator 2842 01:02:18,500 --> 01:02:18,510 way you can always use the not operator 2843 01:02:18,510 --> 01:02:20,180 way you can always use the not operator here let's say if you want to get the 2844 01:02:20,180 --> 01:02:20,190 here let's say if you want to get the 2845 01:02:20,190 --> 01:02:22,759 here let's say if you want to get the customers whose phone numbers don't end 2846 01:02:22,759 --> 01:02:22,769 customers whose phone numbers don't end 2847 01:02:22,769 --> 01:02:26,180 customers whose phone numbers don't end with nine so we simply prefix like with 2848 01:02:26,180 --> 01:02:26,190 with nine so we simply prefix like with 2849 01:02:26,190 --> 01:02:29,059 with nine so we simply prefix like with not now if we execute this query one 2850 01:02:29,059 --> 01:02:29,069 not now if we execute this query one 2851 01:02:29,069 --> 01:02:32,480 not now if we execute this query one more time we get all the other customers 2852 01:02:32,480 --> 01:02:32,490 more time we get all the other customers 2853 01:02:32,490 --> 01:02:38,469 more time we get all the other customers and the database 2854 01:02:38,469 --> 01:02:38,479 2855 01:02:38,479 --> 01:02:40,910 in the last tutorial you learn about the 2856 01:02:40,910 --> 01:02:40,920 in the last tutorial you learn about the 2857 01:02:40,920 --> 01:02:43,910 in the last tutorial you learn about the like operator in sequel so as another 2858 01:02:43,910 --> 01:02:43,920 like operator in sequel so as another 2859 01:02:43,920 --> 01:02:45,829 like operator in sequel so as another example let's say we want to search for 2860 01:02:45,829 --> 01:02:45,839 example let's say we want to search for 2861 01:02:45,839 --> 01:02:48,380 example let's say we want to search for the customers who have the word field in 2862 01:02:48,380 --> 01:02:48,390 the customers who have the word field in 2863 01:02:48,390 --> 01:02:51,229 the customers who have the word field in their last name so we type out a where 2864 01:02:51,229 --> 01:02:51,239 their last name so we type out a where 2865 01:02:51,239 --> 01:02:56,329 their last name so we type out a where clause like this where last name like % 2866 01:02:56,329 --> 01:02:56,339 clause like this where last name like % 2867 01:02:56,339 --> 01:03:00,380 clause like this where last name like % field % so the word field can be 2868 01:03:00,380 --> 01:03:00,390 field % so the word field can be 2869 01:03:00,390 --> 01:03:02,930 field % so the word field can be anywhere in the last name let's execute 2870 01:03:02,930 --> 01:03:02,940 anywhere in the last name let's execute 2871 01:03:02,940 --> 01:03:04,699 anywhere in the last name let's execute this query we get only one customer 2872 01:03:04,699 --> 01:03:04,709 this query we get only one customer 2873 01:03:04,709 --> 01:03:07,279 this query we get only one customer beautiful now we also have another 2874 01:03:07,279 --> 01:03:07,289 beautiful now we also have another 2875 01:03:07,289 --> 01:03:12,259 beautiful now we also have another operator in MySQL that is reg X which is 2876 01:03:12,259 --> 01:03:12,269 operator in MySQL that is reg X which is 2877 01:03:12,269 --> 01:03:14,749 operator in MySQL that is reg X which is short for regular expression and regular 2878 01:03:14,749 --> 01:03:14,759 short for regular expression and regular 2879 01:03:14,759 --> 01:03:16,699 short for regular expression and regular expressions are extremely powerful when 2880 01:03:16,699 --> 01:03:16,709 expressions are extremely powerful when 2881 01:03:16,709 --> 01:03:19,130 expressions are extremely powerful when it comes to searching for Strings so 2882 01:03:19,130 --> 01:03:19,140 it comes to searching for Strings so 2883 01:03:19,140 --> 01:03:21,289 it comes to searching for Strings so they allow us to search for more complex 2884 01:03:21,289 --> 01:03:21,299 they allow us to search for more complex 2885 01:03:21,299 --> 01:03:24,140 they allow us to search for more complex patterns here's an example if I want to 2886 01:03:24,140 --> 01:03:24,150 patterns here's an example if I want to 2887 01:03:24,150 --> 01:03:27,559 patterns here's an example if I want to rewrite this last where clause using a 2888 01:03:27,559 --> 01:03:27,569 rewrite this last where clause using a 2889 01:03:27,569 --> 01:03:29,209 rewrite this last where clause using a regular expression it looks like this 2890 01:03:29,209 --> 01:03:29,219 regular expression it looks like this 2891 01:03:29,219 --> 01:03:35,329 regular expression it looks like this where last name are AG exp now hitting 2892 01:03:35,329 --> 01:03:35,339 where last name are AG exp now hitting 2893 01:03:35,339 --> 01:03:37,670 where last name are AG exp now hitting our string pattern we don't have to type 2894 01:03:37,670 --> 01:03:37,680 our string pattern we don't have to type 2895 01:03:37,680 --> 01:03:40,370 our string pattern we don't have to type out the percent signs we only type out 2896 01:03:40,370 --> 01:03:40,380 out the percent signs we only type out 2897 01:03:40,380 --> 01:03:43,009 out the percent signs we only type out field so what we have on line 4 is 2898 01:03:43,009 --> 01:03:43,019 field so what we have on line 4 is 2899 01:03:43,019 --> 01:03:45,650 field so what we have on line 4 is exactly identical to what we have on 2900 01:03:45,650 --> 01:03:45,660 exactly identical to what we have on 2901 01:03:45,660 --> 01:03:49,249 exactly identical to what we have on line 3 let's execute this query we get 2902 01:03:49,249 --> 01:03:49,259 line 3 let's execute this query we get 2903 01:03:49,259 --> 01:03:51,469 line 3 let's execute this query we get the same result beautiful now here in 2904 01:03:51,469 --> 01:03:51,479 the same result beautiful now here in 2905 01:03:51,479 --> 01:03:53,329 the same result beautiful now here in regular expressions we have additional 2906 01:03:53,329 --> 01:03:53,339 regular expressions we have additional 2907 01:03:53,339 --> 01:03:55,279 regular expressions we have additional characters that we don't have when we 2908 01:03:55,279 --> 01:03:55,289 characters that we don't have when we 2909 01:03:55,289 --> 01:03:57,920 characters that we don't have when we use the like operator for example we can 2910 01:03:57,920 --> 01:03:57,930 use the like operator for example we can 2911 01:03:57,930 --> 01:04:00,319 use the like operator for example we can use the caret sign to indicate the 2912 01:04:00,319 --> 01:04:00,329 use the caret sign to indicate the 2913 01:04:00,329 --> 01:04:03,380 use the caret sign to indicate the beginning of a string so if I put a 2914 01:04:03,380 --> 01:04:03,390 beginning of a string so if I put a 2915 01:04:03,390 --> 01:04:07,370 beginning of a string so if I put a caret just before the word filled that 2916 01:04:07,370 --> 01:04:07,380 caret just before the word filled that 2917 01:04:07,380 --> 01:04:09,739 caret just before the word filled that means our last name must start with 2918 01:04:09,739 --> 01:04:09,749 means our last name must start with 2919 01:04:09,749 --> 01:04:12,680 means our last name must start with field obviously if we execute this query 2920 01:04:12,680 --> 01:04:12,690 field obviously if we execute this query 2921 01:04:12,690 --> 01:04:14,660 field obviously if we execute this query we don't get any one that matches this 2922 01:04:14,660 --> 01:04:14,670 we don't get any one that matches this 2923 01:04:14,670 --> 01:04:17,390 we don't get any one that matches this criteria so we use the caret sign to 2924 01:04:17,390 --> 01:04:17,400 criteria so we use the caret sign to 2925 01:04:17,400 --> 01:04:19,910 criteria so we use the caret sign to present the beginning of a string we 2926 01:04:19,910 --> 01:04:19,920 present the beginning of a string we 2927 01:04:19,920 --> 01:04:22,819 present the beginning of a string we also have a dollar sign to represent the 2928 01:04:22,819 --> 01:04:22,829 also have a dollar sign to represent the 2929 01:04:22,829 --> 01:04:25,160 also have a dollar sign to represent the end of a string so this pattern means 2930 01:04:25,160 --> 01:04:25,170 end of a string so this pattern means 2931 01:04:25,170 --> 01:04:28,069 end of a string so this pattern means the last name must end with field let's 2932 01:04:28,069 --> 01:04:28,079 the last name must end with field let's 2933 01:04:28,079 --> 01:04:30,410 the last name must end with field let's execute this query we get the same 2934 01:04:30,410 --> 01:04:30,420 execute this query we get the same 2935 01:04:30,420 --> 01:04:32,930 execute this query we get the same result as before now we can also search 2936 01:04:32,930 --> 01:04:32,940 result as before now we can also search 2937 01:04:32,940 --> 01:04:35,329 result as before now we can also search for multiple words here for example 2938 01:04:35,329 --> 01:04:35,339 for multiple words here for example 2939 01:04:35,339 --> 01:04:36,859 for multiple words here for example let's say we want to find the customers 2940 01:04:36,859 --> 01:04:36,869 let's say we want to find the customers 2941 01:04:36,869 --> 01:04:39,739 let's say we want to find the customers who have the words filled or Mac in 2942 01:04:39,739 --> 01:04:39,749 who have the words filled or Mac in 2943 01:04:39,749 --> 01:04:42,890 who have the words filled or Mac in their last name so we use a pipe a 2944 01:04:42,890 --> 01:04:42,900 their last name so we use a pipe a 2945 01:04:42,900 --> 01:04:46,039 their last name so we use a pipe a vertical bar and type out another 2946 01:04:46,039 --> 01:04:46,049 vertical bar and type out another 2947 01:04:46,049 --> 01:04:47,749 vertical bar and type out another pattern 2948 01:04:47,749 --> 01:04:47,759 pattern 2949 01:04:47,759 --> 01:04:50,419 pattern let's execute this quay so here we have 2950 01:04:50,419 --> 01:04:50,429 let's execute this quay so here we have 2951 01:04:50,429 --> 01:04:52,279 let's execute this quay so here we have two customers one of them has the word 2952 01:04:52,279 --> 01:04:52,289 two customers one of them has the word 2953 01:04:52,289 --> 01:04:54,949 two customers one of them has the word Mack the other has the word filled in 2954 01:04:54,949 --> 01:04:54,959 Mack the other has the word filled in 2955 01:04:54,959 --> 01:04:57,319 Mack the other has the word filled in their last name now we can take this to 2956 01:04:57,319 --> 01:04:57,329 their last name now we can take this to 2957 01:04:57,329 --> 01:04:58,849 their last name now we can take this to the next level let's say we want to find 2958 01:04:58,849 --> 01:04:58,859 the next level let's say we want to find 2959 01:04:58,859 --> 01:05:01,219 the next level let's say we want to find the customers who have the words filled 2960 01:05:01,219 --> 01:05:01,229 the customers who have the words filled 2961 01:05:01,229 --> 01:05:05,029 the customers who have the words filled or match or rose in their last name 2962 01:05:05,029 --> 01:05:05,039 or match or rose in their last name 2963 01:05:05,039 --> 01:05:07,699 or match or rose in their last name let's execute the query we get three 2964 01:05:07,699 --> 01:05:07,709 let's execute the query we get three 2965 01:05:07,709 --> 01:05:10,729 let's execute the query we get three customers beautiful so we use a pipe or 2966 01:05:10,729 --> 01:05:10,739 customers beautiful so we use a pipe or 2967 01:05:10,739 --> 01:05:13,489 customers beautiful so we use a pipe or a vertical bar to represent multiple 2968 01:05:13,489 --> 01:05:13,499 a vertical bar to represent multiple 2969 01:05:13,499 --> 01:05:15,769 a vertical bar to represent multiple search patterns now as another example 2970 01:05:15,769 --> 01:05:15,779 search patterns now as another example 2971 01:05:15,779 --> 01:05:18,259 search patterns now as another example we can change our first search pattern 2972 01:05:18,259 --> 01:05:18,269 we can change our first search pattern 2973 01:05:18,269 --> 01:05:21,469 we can change our first search pattern to something like this now this pattern 2974 01:05:21,469 --> 01:05:21,479 to something like this now this pattern 2975 01:05:21,479 --> 01:05:23,870 to something like this now this pattern means the last name should either start 2976 01:05:23,870 --> 01:05:23,880 means the last name should either start 2977 01:05:23,880 --> 01:05:27,469 means the last name should either start with the word field or it should have 2978 01:05:27,469 --> 01:05:27,479 with the word field or it should have 2979 01:05:27,479 --> 01:05:30,199 with the word field or it should have the word Mack in it or it should have 2980 01:05:30,199 --> 01:05:30,209 the word Mack in it or it should have 2981 01:05:30,209 --> 01:05:32,589 the word Mack in it or it should have the word rose let's execute the query 2982 01:05:32,589 --> 01:05:32,599 the word rose let's execute the query 2983 01:05:32,599 --> 01:05:35,509 the word rose let's execute the query now we get only two customers because 2984 01:05:35,509 --> 01:05:35,519 now we get only two customers because 2985 01:05:35,519 --> 01:05:37,489 now we get only two customers because our customer with the last name brush 2986 01:05:37,489 --> 01:05:37,499 our customer with the last name brush 2987 01:05:37,499 --> 01:05:40,669 our customer with the last name brush field doesn't match this pattern however 2988 01:05:40,669 --> 01:05:40,679 field doesn't match this pattern however 2989 01:05:40,679 --> 01:05:43,699 field doesn't match this pattern however if we change our first pattern to field 2990 01:05:43,699 --> 01:05:43,709 if we change our first pattern to field 2991 01:05:43,709 --> 01:05:46,729 if we change our first pattern to field dollar sign and execute the query we get 2992 01:05:46,729 --> 01:05:46,739 dollar sign and execute the query we get 2993 01:05:46,739 --> 01:05:49,549 dollar sign and execute the query we get three people here three customers so 2994 01:05:49,549 --> 01:05:49,559 three people here three customers so 2995 01:05:49,559 --> 01:05:50,889 three people here three customers so this is how we can combine multiple 2996 01:05:50,889 --> 01:05:50,899 this is how we can combine multiple 2997 01:05:50,899 --> 01:05:53,359 this is how we can combine multiple special characters when building a 2998 01:05:53,359 --> 01:05:53,369 special characters when building a 2999 01:05:53,369 --> 01:05:55,669 special characters when building a complex pattern now let's look at 3000 01:05:55,669 --> 01:05:55,679 complex pattern now let's look at 3001 01:05:55,679 --> 01:05:57,529 complex pattern now let's look at another example let's say we want to 3002 01:05:57,529 --> 01:05:57,539 another example let's say we want to 3003 01:05:57,539 --> 01:05:59,839 another example let's say we want to search for customers who have an e in 3004 01:05:59,839 --> 01:05:59,849 search for customers who have an e in 3005 01:05:59,849 --> 01:06:01,789 search for customers who have an e in their last name so these are all the 3006 01:06:01,789 --> 01:06:01,799 their last name so these are all the 3007 01:06:01,799 --> 01:06:04,399 their last name so these are all the people all right now let's say we want 3008 01:06:04,399 --> 01:06:04,409 people all right now let's say we want 3009 01:06:04,409 --> 01:06:06,799 people all right now let's say we want to make sure that before the letter e we 3010 01:06:06,799 --> 01:06:06,809 to make sure that before the letter e we 3011 01:06:06,809 --> 01:06:10,639 to make sure that before the letter e we should either have AG or an I so this is 3012 01:06:10,639 --> 01:06:10,649 should either have AG or an I so this is 3013 01:06:10,649 --> 01:06:13,609 should either have AG or an I so this is where we use square brackets and inside 3014 01:06:13,609 --> 01:06:13,619 where we use square brackets and inside 3015 01:06:13,619 --> 01:06:15,649 where we use square brackets and inside the brackets we add multiple characters 3016 01:06:15,649 --> 01:06:15,659 the brackets we add multiple characters 3017 01:06:15,659 --> 01:06:18,739 the brackets we add multiple characters like G I M and that matches any 3018 01:06:18,739 --> 01:06:18,749 like G I M and that matches any 3019 01:06:18,749 --> 01:06:24,409 like G I M and that matches any customers who have GE or ie or M II in 3020 01:06:24,409 --> 01:06:24,419 customers who have GE or ie or M II in 3021 01:06:24,419 --> 01:06:26,299 customers who have GE or ie or M II in their last name so any of these 3022 01:06:26,299 --> 01:06:26,309 their last name so any of these 3023 01:06:26,309 --> 01:06:29,929 their last name so any of these characters can come before e now let's 3024 01:06:29,929 --> 01:06:29,939 characters can come before e now let's 3025 01:06:29,939 --> 01:06:33,649 characters can come before e now let's execute this query there you go we only 3026 01:06:33,649 --> 01:06:33,659 execute this query there you go we only 3027 01:06:33,659 --> 01:06:36,499 execute this query there you go we only get two customers in the first example 3028 01:06:36,499 --> 01:06:36,509 get two customers in the first example 3029 01:06:36,509 --> 01:06:39,469 get two customers in the first example before e we have AI which is one of the 3030 01:06:39,469 --> 01:06:39,479 before e we have AI which is one of the 3031 01:06:39,479 --> 01:06:41,959 before e we have AI which is one of the characters inside the brackets in the 3032 01:06:41,959 --> 01:06:41,969 characters inside the brackets in the 3033 01:06:41,969 --> 01:06:44,809 characters inside the brackets in the second example before E we have a G 3034 01:06:44,809 --> 01:06:44,819 second example before E we have a G 3035 01:06:44,819 --> 01:06:47,179 second example before E we have a G which is also another valid character 3036 01:06:47,179 --> 01:06:47,189 which is also another valid character 3037 01:06:47,189 --> 01:06:49,789 which is also another valid character before e now once again the square 3038 01:06:49,789 --> 01:06:49,799 before e now once again the square 3039 01:06:49,799 --> 01:06:52,099 before e now once again the square brackets don't have to be before E we 3040 01:06:52,099 --> 01:06:52,109 brackets don't have to be before E we 3041 01:06:52,109 --> 01:06:54,979 brackets don't have to be before E we could add them after E so any customers 3042 01:06:54,979 --> 01:06:54,989 could add them after E so any customers 3043 01:06:54,989 --> 01:06:59,749 could add them after E so any customers who have ephod buy an F or an M or a Q 3044 01:06:59,749 --> 01:06:59,759 who have ephod buy an F or an M or a Q 3045 01:06:59,759 --> 01:07:01,770 who have ephod buy an F or an M or a Q in their last name 3046 01:07:01,770 --> 01:07:01,780 in their last name 3047 01:07:01,780 --> 01:07:03,330 in their last name can be returned with this pattern 3048 01:07:03,330 --> 01:07:03,340 can be returned with this pattern 3049 01:07:03,340 --> 01:07:05,099 can be returned with this pattern obviously we don't have anyone in the 3050 01:07:05,099 --> 01:07:05,109 obviously we don't have anyone in the 3051 01:07:05,109 --> 01:07:07,770 obviously we don't have anyone in the database so this is how we use square 3052 01:07:07,770 --> 01:07:07,780 database so this is how we use square 3053 01:07:07,780 --> 01:07:10,680 database so this is how we use square brackets now we can also supply a range 3054 01:07:10,680 --> 01:07:10,690 brackets now we can also supply a range 3055 01:07:10,690 --> 01:07:13,440 brackets now we can also supply a range of characters for example we can have e 3056 01:07:13,440 --> 01:07:13,450 of characters for example we can have e 3057 01:07:13,450 --> 01:07:15,870 of characters for example we can have e and just before if you want to have any 3058 01:07:15,870 --> 01:07:15,880 and just before if you want to have any 3059 01:07:15,880 --> 01:07:20,040 and just before if you want to have any characters from a to H we don't have to 3060 01:07:20,040 --> 01:07:20,050 characters from a to H we don't have to 3061 01:07:20,050 --> 01:07:23,580 characters from a to H we don't have to type them out explicitly like ABCD efg 3062 01:07:23,580 --> 01:07:23,590 type them out explicitly like ABCD efg 3063 01:07:23,590 --> 01:07:26,670 type them out explicitly like ABCD efg that's very verbose so we can type out a 3064 01:07:26,670 --> 01:07:26,680 that's very verbose so we can type out a 3065 01:07:26,680 --> 01:07:29,550 that's very verbose so we can type out a to H and now if you execute this query 3066 01:07:29,550 --> 01:07:29,560 to H and now if you execute this query 3067 01:07:29,560 --> 01:07:33,060 to H and now if you execute this query we get these three people so let's 3068 01:07:33,060 --> 01:07:33,070 we get these three people so let's 3069 01:07:33,070 --> 01:07:35,130 we get these three people so let's quickly recap everything you learn about 3070 01:07:35,130 --> 01:07:35,140 quickly recap everything you learn about 3071 01:07:35,140 --> 01:07:38,220 quickly recap everything you learn about regular expressions in this tutorial we 3072 01:07:38,220 --> 01:07:38,230 regular expressions in this tutorial we 3073 01:07:38,230 --> 01:07:40,320 regular expressions in this tutorial we use a carrot to present the beginning of 3074 01:07:40,320 --> 01:07:40,330 use a carrot to present the beginning of 3075 01:07:40,330 --> 01:07:43,349 use a carrot to present the beginning of a string so beginning we use a dollar 3076 01:07:43,349 --> 01:07:43,359 a string so beginning we use a dollar 3077 01:07:43,359 --> 01:07:46,109 a string so beginning we use a dollar sign to represent the end of a string we 3078 01:07:46,109 --> 01:07:46,119 sign to represent the end of a string we 3079 01:07:46,119 --> 01:07:48,660 sign to represent the end of a string we use a vertical bar or a pipe to 3080 01:07:48,660 --> 01:07:48,670 use a vertical bar or a pipe to 3081 01:07:48,670 --> 01:07:51,540 use a vertical bar or a pipe to represent a logical or so we can supply 3082 01:07:51,540 --> 01:07:51,550 represent a logical or so we can supply 3083 01:07:51,550 --> 01:07:54,960 represent a logical or so we can supply multiple search patterns we use square 3084 01:07:54,960 --> 01:07:54,970 multiple search patterns we use square 3085 01:07:54,970 --> 01:07:57,450 multiple search patterns we use square brackets to match any single characters 3086 01:07:57,450 --> 01:07:57,460 brackets to match any single characters 3087 01:07:57,460 --> 01:08:00,930 brackets to match any single characters listed in the brackets and finally we 3088 01:08:00,930 --> 01:08:00,940 listed in the brackets and finally we 3089 01:08:00,940 --> 01:08:03,180 listed in the brackets and finally we use square brackets with a hyphen to 3090 01:08:03,180 --> 01:08:03,190 use square brackets with a hyphen to 3091 01:08:03,190 --> 01:08:05,430 use square brackets with a hyphen to present a range so any characters from a 3092 01:08:05,430 --> 01:08:05,440 present a range so any characters from a 3093 01:08:05,440 --> 01:08:09,180 present a range so any characters from a to let's say F but technically my school 3094 01:08:09,180 --> 01:08:09,190 to let's say F but technically my school 3095 01:08:09,190 --> 01:08:11,730 to let's say F but technically my school supports more special characters but 3096 01:08:11,730 --> 01:08:11,740 supports more special characters but 3097 01:08:11,740 --> 01:08:13,380 supports more special characters but quite honestly the ones that I've listed 3098 01:08:13,380 --> 01:08:13,390 quite honestly the ones that I've listed 3099 01:08:13,390 --> 01:08:14,730 quite honestly the ones that I've listed in this tutorial are the ones that 3100 01:08:14,730 --> 01:08:14,740 in this tutorial are the ones that 3101 01:08:14,740 --> 01:08:17,700 in this tutorial are the ones that you'll be using 90% of the time so just 3102 01:08:17,700 --> 01:08:17,710 you'll be using 90% of the time so just 3103 01:08:17,710 --> 01:08:23,800 you'll be using 90% of the time so just memorize these ad you're good to go 3104 01:08:23,800 --> 01:08:23,810 3105 01:08:23,810 --> 01:08:26,390 quite honestly a lot of beginners find 3106 01:08:26,390 --> 01:08:26,400 quite honestly a lot of beginners find 3107 01:08:26,400 --> 01:08:27,940 quite honestly a lot of beginners find the syntax for regular expressions 3108 01:08:27,940 --> 01:08:27,950 the syntax for regular expressions 3109 01:08:27,950 --> 01:08:30,230 the syntax for regular expressions confusing so in this video I'm gonna 3110 01:08:30,230 --> 01:08:30,240 confusing so in this video I'm gonna 3111 01:08:30,240 --> 01:08:31,820 confusing so in this video I'm gonna give you four exercises that I have 3112 01:08:31,820 --> 01:08:31,830 give you four exercises that I have 3113 01:08:31,830 --> 01:08:33,830 give you four exercises that I have carefully designed to help you quickly 3114 01:08:33,830 --> 01:08:33,840 carefully designed to help you quickly 3115 01:08:33,840 --> 01:08:35,300 carefully designed to help you quickly learn about this syntax 3116 01:08:35,300 --> 01:08:35,310 learn about this syntax 3117 01:08:35,310 --> 01:08:37,460 learn about this syntax here's the first exercise get the 3118 01:08:37,460 --> 01:08:37,470 here's the first exercise get the 3119 01:08:37,470 --> 01:08:40,460 here's the first exercise get the customers whose first names are Elka or 3120 01:08:40,460 --> 01:08:40,470 customers whose first names are Elka or 3121 01:08:40,470 --> 01:08:44,020 customers whose first names are Elka or amber I note that this is amber with a u 3122 01:08:44,020 --> 01:08:44,030 amber I note that this is amber with a u 3123 01:08:44,030 --> 01:08:46,760 amber I note that this is amber with a u now for the second exercise return the 3124 01:08:46,760 --> 01:08:46,770 now for the second exercise return the 3125 01:08:46,770 --> 01:08:49,550 now for the second exercise return the customers whose last names and with E Y 3126 01:08:49,550 --> 01:08:49,560 customers whose last names and with E Y 3127 01:08:49,560 --> 01:08:54,080 customers whose last names and with E Y or o n here's the third exercise get the 3128 01:08:54,080 --> 01:08:54,090 or o n here's the third exercise get the 3129 01:08:54,090 --> 01:08:56,900 or o n here's the third exercise get the customers whose last names start with my 3130 01:08:56,900 --> 01:08:56,910 customers whose last names start with my 3131 01:08:56,910 --> 01:09:00,920 customers whose last names start with my or it contains s E and finally as the 3132 01:09:00,920 --> 01:09:00,930 or it contains s E and finally as the 3133 01:09:00,930 --> 01:09:03,470 or it contains s E and finally as the last exercise return the customers whose 3134 01:09:03,470 --> 01:09:03,480 last exercise return the customers whose 3135 01:09:03,480 --> 01:09:07,160 last exercise return the customers whose last names contain be followed by R or 3136 01:09:07,160 --> 01:09:07,170 last names contain be followed by R or 3137 01:09:07,170 --> 01:09:11,270 last names contain be followed by R or you so go ahead and spend 2 to 3 minutes 3138 01:09:11,270 --> 01:09:11,280 you so go ahead and spend 2 to 3 minutes 3139 01:09:11,280 --> 01:09:13,100 you so go ahead and spend 2 to 3 minutes on this exercise when you're done come 3140 01:09:13,100 --> 01:09:13,110 on this exercise when you're done come 3141 01:09:13,110 --> 01:09:16,050 on this exercise when you're done come back continue watching 3142 01:09:16,050 --> 01:09:16,060 3143 01:09:16,060 --> 01:09:19,099 you 3144 01:09:19,099 --> 01:09:19,109 3145 01:09:19,109 --> 01:09:21,599 all right let's knock out the first 3146 01:09:21,599 --> 01:09:21,609 all right let's knock out the first 3147 01:09:21,609 --> 01:09:26,070 all right let's knock out the first exercise so we want to get all whoops 3148 01:09:26,070 --> 01:09:26,080 exercise so we want to get all whoops 3149 01:09:26,080 --> 01:09:28,020 exercise so we want to get all whoops there's a see here select star from 3150 01:09:28,020 --> 01:09:28,030 there's a see here select star from 3151 01:09:28,030 --> 01:09:32,610 there's a see here select star from customers we're first name regular 3152 01:09:32,610 --> 01:09:32,620 customers we're first name regular 3153 01:09:32,620 --> 01:09:35,550 customers we're first name regular expression and here's our pattern we 3154 01:09:35,550 --> 01:09:35,560 expression and here's our pattern we 3155 01:09:35,560 --> 01:09:38,070 expression and here's our pattern we want to search for two words either Elka 3156 01:09:38,070 --> 01:09:38,080 want to search for two words either Elka 3157 01:09:38,080 --> 01:09:39,870 want to search for two words either Elka or amber 3158 01:09:39,870 --> 01:09:39,880 or amber 3159 01:09:39,880 --> 01:09:42,710 or amber simple as that let's execute this query 3160 01:09:42,710 --> 01:09:42,720 simple as that let's execute this query 3161 01:09:42,720 --> 01:09:45,390 simple as that let's execute this query we should get two customers there you go 3162 01:09:45,390 --> 01:09:45,400 we should get two customers there you go 3163 01:09:45,400 --> 01:09:49,079 we should get two customers there you go amber and Elka all right now let's knock 3164 01:09:49,079 --> 01:09:49,089 amber and Elka all right now let's knock 3165 01:09:49,089 --> 01:09:51,540 amber and Elka all right now let's knock out the second exercise so I'm gonna 3166 01:09:51,540 --> 01:09:51,550 out the second exercise so I'm gonna 3167 01:09:51,550 --> 01:09:54,420 out the second exercise so I'm gonna delete this we don't need it anymore so 3168 01:09:54,420 --> 01:09:54,430 delete this we don't need it anymore so 3169 01:09:54,430 --> 01:09:57,120 delete this we don't need it anymore so we want to get the customers select star 3170 01:09:57,120 --> 01:09:57,130 we want to get the customers select star 3171 01:09:57,130 --> 01:10:02,400 we want to get the customers select star from customers where last name should 3172 01:10:02,400 --> 01:10:02,410 from customers where last name should 3173 01:10:02,410 --> 01:10:06,870 from customers where last name should end with either a Y or Oh n so in the 3174 01:10:06,870 --> 01:10:06,880 end with either a Y or Oh n so in the 3175 01:10:06,880 --> 01:10:09,480 end with either a Y or Oh n so in the search pattern we type out ey followed 3176 01:10:09,480 --> 01:10:09,490 search pattern we type out ey followed 3177 01:10:09,490 --> 01:10:11,670 search pattern we type out ey followed by a dollar sign to indicate the end of 3178 01:10:11,670 --> 01:10:11,680 by a dollar sign to indicate the end of 3179 01:10:11,680 --> 01:10:14,790 by a dollar sign to indicate the end of your string then we had a vertical bar 3180 01:10:14,790 --> 01:10:14,800 your string then we had a vertical bar 3181 01:10:14,800 --> 01:10:17,670 your string then we had a vertical bar to supply the second search pattern so o 3182 01:10:17,670 --> 01:10:17,680 to supply the second search pattern so o 3183 01:10:17,680 --> 01:10:21,000 to supply the second search pattern so o N and once again a dollar sign let's 3184 01:10:21,000 --> 01:10:21,010 N and once again a dollar sign let's 3185 01:10:21,010 --> 01:10:23,310 N and once again a dollar sign let's execute this query oops actually I 3186 01:10:23,310 --> 01:10:23,320 execute this query oops actually I 3187 01:10:23,320 --> 01:10:26,430 execute this query oops actually I forgot to type out regular expression 3188 01:10:26,430 --> 01:10:26,440 forgot to type out regular expression 3189 01:10:26,440 --> 01:10:29,660 forgot to type out regular expression there you go so let's execute this query 3190 01:10:29,660 --> 01:10:29,670 there you go so let's execute this query 3191 01:10:29,670 --> 01:10:34,560 there you go so let's execute this query and we should get these for customers 3192 01:10:34,560 --> 01:10:34,570 and we should get these for customers 3193 01:10:34,570 --> 01:10:38,400 and we should get these for customers with IDs one three five and seven the 3194 01:10:38,400 --> 01:10:38,410 with IDs one three five and seven the 3195 01:10:38,410 --> 01:10:40,500 with IDs one three five and seven the first three their last names and with E 3196 01:10:40,500 --> 01:10:40,510 first three their last names and with E 3197 01:10:40,510 --> 01:10:44,130 first three their last names and with E Y and the last customer his or her last 3198 01:10:44,130 --> 01:10:44,140 Y and the last customer his or her last 3199 01:10:44,140 --> 01:10:48,330 Y and the last customer his or her last name ends with Oh n all right now let's 3200 01:10:48,330 --> 01:10:48,340 name ends with Oh n all right now let's 3201 01:10:48,340 --> 01:10:50,370 name ends with Oh n all right now let's work on the third exercise so I'm just 3202 01:10:50,370 --> 01:10:50,380 work on the third exercise so I'm just 3203 01:10:50,380 --> 01:10:52,680 work on the third exercise so I'm just gonna change the regular expression here 3204 01:10:52,680 --> 01:10:52,690 gonna change the regular expression here 3205 01:10:52,690 --> 01:10:55,020 gonna change the regular expression here we want to get the customers whose last 3206 01:10:55,020 --> 01:10:55,030 we want to get the customers whose last 3207 01:10:55,030 --> 01:10:59,640 we want to get the customers whose last name starts with my or contains se so we 3208 01:10:59,640 --> 01:10:59,650 name starts with my or contains se so we 3209 01:10:59,650 --> 01:11:02,280 name starts with my or contains se so we use a carrot to indicate the beginning 3210 01:11:02,280 --> 01:11:02,290 use a carrot to indicate the beginning 3211 01:11:02,290 --> 01:11:05,100 use a carrot to indicate the beginning of our string so it should start with my 3212 01:11:05,100 --> 01:11:05,110 of our string so it should start with my 3213 01:11:05,110 --> 01:11:08,910 of our string so it should start with my or it should contain as e again very 3214 01:11:08,910 --> 01:11:08,920 or it should contain as e again very 3215 01:11:08,920 --> 01:11:14,070 or it should contain as e again very easy let's execute this query and we get 3216 01:11:14,070 --> 01:11:14,080 easy let's execute this query and we get 3217 01:11:14,080 --> 01:11:16,740 easy let's execute this query and we get the customers with IDs four eight and 3218 01:11:16,740 --> 01:11:16,750 the customers with IDs four eight and 3219 01:11:16,750 --> 01:11:20,250 the customers with IDs four eight and ten and finally we want to get the 3220 01:11:20,250 --> 01:11:20,260 ten and finally we want to get the 3221 01:11:20,260 --> 01:11:24,510 ten and finally we want to get the customers whose last names contain B so 3222 01:11:24,510 --> 01:11:24,520 customers whose last names contain B so 3223 01:11:24,520 --> 01:11:26,730 customers whose last names contain B so let's change the search pattern we 3224 01:11:26,730 --> 01:11:26,740 let's change the search pattern we 3225 01:11:26,740 --> 01:11:30,360 let's change the search pattern we should have a be followed by our or you 3226 01:11:30,360 --> 01:11:30,370 should have a be followed by our or you 3227 01:11:30,370 --> 01:11:32,520 should have a be followed by our or you now there are two ways to write this 3228 01:11:32,520 --> 01:11:32,530 now there are two ways to write this 3229 01:11:32,530 --> 01:11:34,649 now there are two ways to write this regular expression we can use square 3230 01:11:34,649 --> 01:11:34,659 regular expression we can use square 3231 01:11:34,659 --> 01:11:37,799 regular expression we can use square brackets so we have be followed by our 3232 01:11:37,799 --> 01:11:37,809 brackets so we have be followed by our 3233 01:11:37,809 --> 01:11:41,310 brackets so we have be followed by our or you that's one way the other way is 3234 01:11:41,310 --> 01:11:41,320 or you that's one way the other way is 3235 01:11:41,320 --> 01:11:46,290 or you that's one way the other way is to use a vertical bar so BR or bu these 3236 01:11:46,290 --> 01:11:46,300 to use a vertical bar so BR or bu these 3237 01:11:46,300 --> 01:11:49,109 to use a vertical bar so BR or bu these are both valid solutions so I hope you 3238 01:11:49,109 --> 01:11:49,119 are both valid solutions so I hope you 3239 01:11:49,119 --> 01:11:51,149 are both valid solutions so I hope you knocked out these exercises in the next 3240 01:11:51,149 --> 01:11:51,159 knocked out these exercises in the next 3241 01:11:51,159 --> 01:11:52,830 knocked out these exercises in the next tutorial I'm gonna show you how to get 3242 01:11:52,830 --> 01:11:52,840 tutorial I'm gonna show you how to get 3243 01:11:52,840 --> 01:11:59,840 tutorial I'm gonna show you how to get the records with missing values 3244 01:11:59,840 --> 01:11:59,850 3245 01:11:59,850 --> 01:12:02,129 in this tutorial I'm gonna show you how 3246 01:12:02,129 --> 01:12:02,139 in this tutorial I'm gonna show you how 3247 01:12:02,139 --> 01:12:03,899 in this tutorial I'm gonna show you how to look for records that Miss an 3248 01:12:03,899 --> 01:12:03,909 to look for records that Miss an 3249 01:12:03,909 --> 01:12:06,419 to look for records that Miss an attribute for example if we select all 3250 01:12:06,419 --> 01:12:06,429 attribute for example if we select all 3251 01:12:06,429 --> 01:12:09,209 attribute for example if we select all the customers in our database we can see 3252 01:12:09,209 --> 01:12:09,219 the customers in our database we can see 3253 01:12:09,219 --> 01:12:12,090 the customers in our database we can see that the customer with ID 5 doesn't have 3254 01:12:12,090 --> 01:12:12,100 that the customer with ID 5 doesn't have 3255 01:12:12,100 --> 01:12:14,459 that the customer with ID 5 doesn't have a phone number so if you look closely 3256 01:12:14,459 --> 01:12:14,469 a phone number so if you look closely 3257 01:12:14,469 --> 01:12:16,979 a phone number so if you look closely here you can see the value null null 3258 01:12:16,979 --> 01:12:16,989 here you can see the value null null 3259 01:12:16,989 --> 01:12:19,830 here you can see the value null null means the absence of the value now let's 3260 01:12:19,830 --> 01:12:19,840 means the absence of the value now let's 3261 01:12:19,840 --> 01:12:21,000 means the absence of the value now let's say we want to search for all the 3262 01:12:21,000 --> 01:12:21,010 say we want to search for all the 3263 01:12:21,010 --> 01:12:23,370 say we want to search for all the customers who don't have a phone perhaps 3264 01:12:23,370 --> 01:12:23,380 customers who don't have a phone perhaps 3265 01:12:23,380 --> 01:12:24,959 customers who don't have a phone perhaps you want to send them an email and say 3266 01:12:24,959 --> 01:12:24,969 you want to send them an email and say 3267 01:12:24,969 --> 01:12:27,000 you want to send them an email and say hey your phone is missing in our system 3268 01:12:27,000 --> 01:12:27,010 hey your phone is missing in our system 3269 01:12:27,010 --> 01:12:29,879 hey your phone is missing in our system so how can we get this customers that is 3270 01:12:29,879 --> 01:12:29,889 so how can we get this customers that is 3271 01:12:29,889 --> 01:12:32,300 so how can we get this customers that is very easy we use the ease null operator 3272 01:12:32,300 --> 01:12:32,310 very easy we use the ease null operator 3273 01:12:32,310 --> 01:12:36,419 very easy we use the ease null operator so in the where clause we type out where 3274 01:12:36,419 --> 01:12:36,429 so in the where clause we type out where 3275 01:12:36,429 --> 01:12:40,530 so in the where clause we type out where phone is not now let's execute this 3276 01:12:40,530 --> 01:12:40,540 phone is not now let's execute this 3277 01:12:40,540 --> 01:12:43,800 phone is not now let's execute this query we only get one customer who 3278 01:12:43,800 --> 01:12:43,810 query we only get one customer who 3279 01:12:43,810 --> 01:12:45,750 query we only get one customer who doesn't have a phone now here we can 3280 01:12:45,750 --> 01:12:45,760 doesn't have a phone now here we can 3281 01:12:45,760 --> 01:12:48,149 doesn't have a phone now here we can also use the not operator to get the 3282 01:12:48,149 --> 01:12:48,159 also use the not operator to get the 3283 01:12:48,159 --> 01:12:50,729 also use the not operator to get the customers who do have a phone so we 3284 01:12:50,729 --> 01:12:50,739 customers who do have a phone so we 3285 01:12:50,739 --> 01:12:54,030 customers who do have a phone so we change the condition to is not null 3286 01:12:54,030 --> 01:12:54,040 change the condition to is not null 3287 01:12:54,040 --> 01:12:58,140 change the condition to is not null let's execute the query now in the query 3288 01:12:58,140 --> 01:12:58,150 let's execute the query now in the query 3289 01:12:58,150 --> 01:13:00,720 let's execute the query now in the query results every customer does have a phone 3290 01:13:00,720 --> 01:13:00,730 results every customer does have a phone 3291 01:13:00,730 --> 01:13:04,980 results every customer does have a phone number 3292 01:13:04,980 --> 01:13:04,990 3293 01:13:04,990 --> 01:13:07,330 for this exercise I wanted to write a 3294 01:13:07,330 --> 01:13:07,340 for this exercise I wanted to write a 3295 01:13:07,340 --> 01:13:09,250 for this exercise I wanted to write a query to get the orders that are not 3296 01:13:09,250 --> 01:13:09,260 query to get the orders that are not 3297 01:13:09,260 --> 01:13:11,830 query to get the orders that are not shipped yet this is a very useful query 3298 01:13:11,830 --> 01:13:11,840 shipped yet this is a very useful query 3299 01:13:11,840 --> 01:13:13,090 shipped yet this is a very useful query that is used in a lot of real 3300 01:13:13,090 --> 01:13:13,100 that is used in a lot of real 3301 01:13:13,100 --> 01:13:14,890 that is used in a lot of real applications for example let's say 3302 01:13:14,890 --> 01:13:14,900 applications for example let's say 3303 01:13:14,900 --> 01:13:17,230 applications for example let's say you're an admin for an online shop you 3304 01:13:17,230 --> 01:13:17,240 you're an admin for an online shop you 3305 01:13:17,240 --> 01:13:18,550 you're an admin for an online shop you want to see the orders that are not 3306 01:13:18,550 --> 01:13:18,560 want to see the orders that are not 3307 01:13:18,560 --> 01:13:21,190 want to see the orders that are not shipped yet so you can follow them up so 3308 01:13:21,190 --> 01:13:21,200 shipped yet so you can follow them up so 3309 01:13:21,200 --> 01:13:24,580 shipped yet so you can follow them up so write a query to get these orders 3310 01:13:24,580 --> 01:13:24,590 write a query to get these orders 3311 01:13:24,590 --> 01:13:27,940 write a query to get these orders you 3312 01:13:27,940 --> 01:13:27,950 3313 01:13:27,950 --> 01:13:30,650 so here we have the orders table let's 3314 01:13:30,650 --> 01:13:30,660 so here we have the orders table let's 3315 01:13:30,660 --> 01:13:32,600 so here we have the orders table let's have a quick look at the data in this 3316 01:13:32,600 --> 01:13:32,610 have a quick look at the data in this 3317 01:13:32,610 --> 01:13:36,140 have a quick look at the data in this table alright so if you pay close 3318 01:13:36,140 --> 01:13:36,150 table alright so if you pay close 3319 01:13:36,150 --> 01:13:38,300 table alright so if you pay close attention you see some of these orders 3320 01:13:38,300 --> 01:13:38,310 attention you see some of these orders 3321 01:13:38,310 --> 01:13:41,330 attention you see some of these orders don't have a shipped date and these 3322 01:13:41,330 --> 01:13:41,340 don't have a shipped date and these 3323 01:13:41,340 --> 01:13:43,460 don't have a shipped date and these orders also don't have a shipper ID 3324 01:13:43,460 --> 01:13:43,470 orders also don't have a shipper ID 3325 01:13:43,470 --> 01:13:45,860 orders also don't have a shipper ID which is a unique number for identifying 3326 01:13:45,860 --> 01:13:45,870 which is a unique number for identifying 3327 01:13:45,870 --> 01:13:49,130 which is a unique number for identifying the shippers so any order that misses a 3328 01:13:49,130 --> 01:13:49,140 the shippers so any order that misses a 3329 01:13:49,140 --> 01:13:52,220 the shippers so any order that misses a value for the ship date or shipper ID is 3330 01:13:52,220 --> 01:13:52,230 value for the ship date or shipper ID is 3331 01:13:52,230 --> 01:13:54,470 value for the ship date or shipper ID is considered an order that is not shipped 3332 01:13:54,470 --> 01:13:54,480 considered an order that is not shipped 3333 01:13:54,480 --> 01:13:56,540 considered an order that is not shipped so let's go ahead and write a query to 3334 01:13:56,540 --> 01:13:56,550 so let's go ahead and write a query to 3335 01:13:56,550 --> 01:13:59,270 so let's go ahead and write a query to get these orders so back to our query 3336 01:13:59,270 --> 01:13:59,280 get these orders so back to our query 3337 01:13:59,280 --> 01:14:04,810 get these orders so back to our query editor select star from orders where 3338 01:14:04,810 --> 01:14:04,820 editor select star from orders where 3339 01:14:04,820 --> 01:14:09,110 editor select star from orders where shipped underline date is no you could 3340 01:14:09,110 --> 01:14:09,120 shipped underline date is no you could 3341 01:14:09,120 --> 01:14:12,140 shipped underline date is no you could also write shipper ID is no they're both 3342 01:14:12,140 --> 01:14:12,150 also write shipper ID is no they're both 3343 01:14:12,150 --> 01:14:14,420 also write shipper ID is no they're both equally correct so let's execute this 3344 01:14:14,420 --> 01:14:14,430 equally correct so let's execute this 3345 01:14:14,430 --> 01:14:18,530 equally correct so let's execute this query and we should get five orders or 3346 01:14:18,530 --> 01:14:18,540 query and we should get five orders or 3347 01:14:18,540 --> 01:14:26,460 query and we should get five orders or there's one three four six and eight 3348 01:14:26,460 --> 01:14:26,470 3349 01:14:26,470 --> 01:14:28,810 in this tutorial I'm gonna show you how 3350 01:14:28,810 --> 01:14:28,820 in this tutorial I'm gonna show you how 3351 01:14:28,820 --> 01:14:31,750 in this tutorial I'm gonna show you how to sort data in your sequel queries so 3352 01:14:31,750 --> 01:14:31,760 to sort data in your sequel queries so 3353 01:14:31,760 --> 01:14:33,610 to sort data in your sequel queries so here we have a query to select all the 3354 01:14:33,610 --> 01:14:33,620 here we have a query to select all the 3355 01:14:33,620 --> 01:14:35,830 here we have a query to select all the customers from the customers table if 3356 01:14:35,830 --> 01:14:35,840 customers from the customers table if 3357 01:14:35,840 --> 01:14:37,450 customers from the customers table if you look at the query result you can see 3358 01:14:37,450 --> 01:14:37,460 you look at the query result you can see 3359 01:14:37,460 --> 01:14:39,790 you look at the query result you can see that our customers are sorted by their 3360 01:14:39,790 --> 01:14:39,800 that our customers are sorted by their 3361 01:14:39,800 --> 01:14:43,060 that our customers are sorted by their ID so we have customers 1 2 3 4 and so 3362 01:14:43,060 --> 01:14:43,070 ID so we have customers 1 2 3 4 and so 3363 01:14:43,070 --> 01:14:46,000 ID so we have customers 1 2 3 4 and so on this is the default sort corner but 3364 01:14:46,000 --> 01:14:46,010 on this is the default sort corner but 3365 01:14:46,010 --> 01:14:47,950 on this is the default sort corner but we can always change this using the 3366 01:14:47,950 --> 01:14:47,960 we can always change this using the 3367 01:14:47,960 --> 01:14:51,400 we can always change this using the order by clause but first let me explain 3368 01:14:51,400 --> 01:14:51,410 order by clause but first let me explain 3369 01:14:51,410 --> 01:14:53,740 order by clause but first let me explain why the customer ID column is the 3370 01:14:53,740 --> 01:14:53,750 why the customer ID column is the 3371 01:14:53,750 --> 01:14:56,620 why the customer ID column is the default sort color so first I'm going to 3372 01:14:56,620 --> 01:14:56,630 default sort color so first I'm going to 3373 01:14:56,630 --> 01:14:58,990 default sort color so first I'm going to open up the navigator panel on the left 3374 01:14:58,990 --> 01:14:59,000 open up the navigator panel on the left 3375 01:14:59,000 --> 01:15:01,210 open up the navigator panel on the left side here is the customers table now 3376 01:15:01,210 --> 01:15:01,220 side here is the customers table now 3377 01:15:01,220 --> 01:15:03,160 side here is the customers table now let's click on this middle icon here 3378 01:15:03,160 --> 01:15:03,170 let's click on this middle icon here 3379 01:15:03,170 --> 01:15:06,040 let's click on this middle icon here that looks like a tool this opens up our 3380 01:15:06,040 --> 01:15:06,050 that looks like a tool this opens up our 3381 01:15:06,050 --> 01:15:08,470 that looks like a tool this opens up our customers table in the design mode so 3382 01:15:08,470 --> 01:15:08,480 customers table in the design mode so 3383 01:15:08,480 --> 01:15:10,240 customers table in the design mode so here we can change our columns we can 3384 01:15:10,240 --> 01:15:10,250 here we can change our columns we can 3385 01:15:10,250 --> 01:15:13,000 here we can change our columns we can add new columns or remove existing ones 3386 01:15:13,000 --> 01:15:13,010 add new columns or remove existing ones 3387 01:15:13,010 --> 01:15:15,210 add new columns or remove existing ones or change their name or order and so on 3388 01:15:15,210 --> 01:15:15,220 or change their name or order and so on 3389 01:15:15,220 --> 01:15:17,980 or change their name or order and so on now if you pay close attention you can 3390 01:15:17,980 --> 01:15:17,990 now if you pay close attention you can 3391 01:15:17,990 --> 01:15:20,770 now if you pay close attention you can see a yellow key just before customer ID 3392 01:15:20,770 --> 01:15:20,780 see a yellow key just before customer ID 3393 01:15:20,780 --> 01:15:23,140 see a yellow key just before customer ID this means that this column is the 3394 01:15:23,140 --> 01:15:23,150 this means that this column is the 3395 01:15:23,150 --> 01:15:26,410 this means that this column is the primary key column for this table so in 3396 01:15:26,410 --> 01:15:26,420 primary key column for this table so in 3397 01:15:26,420 --> 01:15:28,870 primary key column for this table so in relational databases every table should 3398 01:15:28,870 --> 01:15:28,880 relational databases every table should 3399 01:15:28,880 --> 01:15:31,300 relational databases every table should have a primary key column and the values 3400 01:15:31,300 --> 01:15:31,310 have a primary key column and the values 3401 01:15:31,310 --> 01:15:33,610 have a primary key column and the values in that column should uniquely identify 3402 01:15:33,610 --> 01:15:33,620 in that column should uniquely identify 3403 01:15:33,620 --> 01:15:36,400 in that column should uniquely identify the records in that table so back to our 3404 01:15:36,400 --> 01:15:36,410 the records in that table so back to our 3405 01:15:36,410 --> 01:15:39,190 the records in that table so back to our query window we can see that the values 3406 01:15:39,190 --> 01:15:39,200 query window we can see that the values 3407 01:15:39,200 --> 01:15:41,620 query window we can see that the values in this column uniquely identify each 3408 01:15:41,620 --> 01:15:41,630 in this column uniquely identify each 3409 01:15:41,630 --> 01:15:44,320 in this column uniquely identify each customer so the customer ID column is 3410 01:15:44,320 --> 01:15:44,330 customer so the customer ID column is 3411 01:15:44,330 --> 01:15:46,420 customer so the customer ID column is the primary key column in this table and 3412 01:15:46,420 --> 01:15:46,430 the primary key column in this table and 3413 01:15:46,430 --> 01:15:48,370 the primary key column in this table and that is why when we write to query 3414 01:15:48,370 --> 01:15:48,380 that is why when we write to query 3415 01:15:48,380 --> 01:15:50,470 that is why when we write to query against this table our customers are 3416 01:15:50,470 --> 01:15:50,480 against this table our customers are 3417 01:15:50,480 --> 01:15:53,830 against this table our customers are sorted by their ID by default now let me 3418 01:15:53,830 --> 01:15:53,840 sorted by their ID by default now let me 3419 01:15:53,840 --> 01:15:55,450 sorted by their ID by default now let me show you how to sort customers by a 3420 01:15:55,450 --> 01:15:55,460 show you how to sort customers by a 3421 01:15:55,460 --> 01:15:58,510 show you how to sort customers by a different column so here in the order by 3422 01:15:58,510 --> 01:15:58,520 different column so here in the order by 3423 01:15:58,520 --> 01:16:00,160 different column so here in the order by clause we type out the name of another 3424 01:16:00,160 --> 01:16:00,170 clause we type out the name of another 3425 01:16:00,170 --> 01:16:02,980 clause we type out the name of another column like first thing let's execute 3426 01:16:02,980 --> 01:16:02,990 column like first thing let's execute 3427 01:16:02,990 --> 01:16:04,900 column like first thing let's execute the query now you can see our customers 3428 01:16:04,900 --> 01:16:04,910 the query now you can see our customers 3429 01:16:04,910 --> 01:16:08,350 the query now you can see our customers are no longer sorted by their ID instead 3430 01:16:08,350 --> 01:16:08,360 are no longer sorted by their ID instead 3431 01:16:08,360 --> 01:16:10,360 are no longer sorted by their ID instead they're sorted by their first name in 3432 01:16:10,360 --> 01:16:10,370 they're sorted by their first name in 3433 01:16:10,370 --> 01:16:12,610 they're sorted by their first name in ascending order now if you want to 3434 01:16:12,610 --> 01:16:12,620 ascending order now if you want to 3435 01:16:12,620 --> 01:16:15,000 ascending order now if you want to reverse the sort order simply type out 3436 01:16:15,000 --> 01:16:15,010 reverse the sort order simply type out 3437 01:16:15,010 --> 01:16:19,180 reverse the sort order simply type out de SC which is short for descending now 3438 01:16:19,180 --> 01:16:19,190 de SC which is short for descending now 3439 01:16:19,190 --> 01:16:21,550 de SC which is short for descending now we are sorting this customers in 3440 01:16:21,550 --> 01:16:21,560 we are sorting this customers in 3441 01:16:21,560 --> 01:16:25,090 we are sorting this customers in descending order ok we can also sort 3442 01:16:25,090 --> 01:16:25,100 descending order ok we can also sort 3443 01:16:25,100 --> 01:16:27,360 descending order ok we can also sort data by multiple columns for example 3444 01:16:27,360 --> 01:16:27,370 data by multiple columns for example 3445 01:16:27,370 --> 01:16:29,680 data by multiple columns for example let's say first we want to sort our 3446 01:16:29,680 --> 01:16:29,690 let's say first we want to sort our 3447 01:16:29,690 --> 01:16:32,860 let's say first we want to sort our customers based on their state and then 3448 01:16:32,860 --> 01:16:32,870 customers based on their state and then 3449 01:16:32,870 --> 01:16:34,330 customers based on their state and then we didn't each state you want to sort 3450 01:16:34,330 --> 01:16:34,340 we didn't each state you want to sort 3451 01:16:34,340 --> 01:16:35,919 we didn't each state you want to sort them by their first name 3452 01:16:35,919 --> 01:16:35,929 them by their first name 3453 01:16:35,929 --> 01:16:39,310 them by their first name so we type out multiple columns here 3454 01:16:39,310 --> 01:16:39,320 so we type out multiple columns here 3455 01:16:39,320 --> 01:16:42,430 so we type out multiple columns here state and first name let's execute the 3456 01:16:42,430 --> 01:16:42,440 state and first name let's execute the 3457 01:16:42,440 --> 01:16:45,430 state and first name let's execute the query now you can see that the first 3458 01:16:45,430 --> 01:16:45,440 query now you can see that the first 3459 01:16:45,440 --> 01:16:47,649 query now you can see that the first state we have here is California 3460 01:16:47,649 --> 01:16:47,659 state we have here is California 3461 01:16:47,659 --> 01:16:50,229 state we have here is California followed by Colorado and now here in 3462 01:16:50,229 --> 01:16:50,239 followed by Colorado and now here in 3463 01:16:50,239 --> 01:16:52,660 followed by Colorado and now here in Florida we have two customers and these 3464 01:16:52,660 --> 01:16:52,670 Florida we have two customers and these 3465 01:16:52,670 --> 01:16:54,910 Florida we have two customers and these customers are sorted by their first name 3466 01:16:54,910 --> 01:16:54,920 customers are sorted by their first name 3467 01:16:54,920 --> 01:16:57,490 customers are sorted by their first name let's have a close look here so first we 3468 01:16:57,490 --> 01:16:57,500 let's have a close look here so first we 3469 01:16:57,500 --> 01:16:59,680 let's have a close look here so first we have amber and then we have this other 3470 01:16:59,680 --> 01:16:59,690 have amber and then we have this other 3471 01:16:59,690 --> 01:17:02,080 have amber and then we have this other customer here now we can also use the 3472 01:17:02,080 --> 01:17:02,090 customer here now we can also use the 3473 01:17:02,090 --> 01:17:04,060 customer here now we can also use the descending argument anywhere here for 3474 01:17:04,060 --> 01:17:04,070 descending argument anywhere here for 3475 01:17:04,070 --> 01:17:06,640 descending argument anywhere here for example we can sort these customers by 3476 01:17:06,640 --> 01:17:06,650 example we can sort these customers by 3477 01:17:06,650 --> 01:17:09,550 example we can sort these customers by their state in descending order and then 3478 01:17:09,550 --> 01:17:09,560 their state in descending order and then 3479 01:17:09,560 --> 01:17:11,350 their state in descending order and then sort them by their first name in 3480 01:17:11,350 --> 01:17:11,360 sort them by their first name in 3481 01:17:11,360 --> 01:17:13,570 sort them by their first name in ascending order or once again in 3482 01:17:13,570 --> 01:17:13,580 ascending order or once again in 3483 01:17:13,580 --> 01:17:14,649 ascending order or once again in descending order 3484 01:17:14,649 --> 01:17:14,659 descending order 3485 01:17:14,659 --> 01:17:16,660 descending order so there are various ways we can sort 3486 01:17:16,660 --> 01:17:16,670 so there are various ways we can sort 3487 01:17:16,670 --> 01:17:18,790 so there are various ways we can sort data now one of the differences between 3488 01:17:18,790 --> 01:17:18,800 data now one of the differences between 3489 01:17:18,800 --> 01:17:21,610 data now one of the differences between MySQL and other database management 3490 01:17:21,610 --> 01:17:21,620 MySQL and other database management 3491 01:17:21,620 --> 01:17:24,220 MySQL and other database management systems is that in MySQL we can sort 3492 01:17:24,220 --> 01:17:24,230 systems is that in MySQL we can sort 3493 01:17:24,230 --> 01:17:27,160 systems is that in MySQL we can sort data by any columns whether that column 3494 01:17:27,160 --> 01:17:27,170 data by any columns whether that column 3495 01:17:27,170 --> 01:17:29,410 data by any columns whether that column is in the Select clause or not for 3496 01:17:29,410 --> 01:17:29,420 is in the Select clause or not for 3497 01:17:29,420 --> 01:17:31,570 is in the Select clause or not for example let's say we only want to select 3498 01:17:31,570 --> 01:17:31,580 example let's say we only want to select 3499 01:17:31,580 --> 01:17:34,240 example let's say we only want to select the first and last name for each 3500 01:17:34,240 --> 01:17:34,250 the first and last name for each 3501 01:17:34,250 --> 01:17:36,700 the first and last name for each customer now we can sort the result by 3502 01:17:36,700 --> 01:17:36,710 customer now we can sort the result by 3503 01:17:36,710 --> 01:17:38,950 customer now we can sort the result by any columns in this table they don't 3504 01:17:38,950 --> 01:17:38,960 any columns in this table they don't 3505 01:17:38,960 --> 01:17:41,050 any columns in this table they don't have to be first name and last name for 3506 01:17:41,050 --> 01:17:41,060 have to be first name and last name for 3507 01:17:41,060 --> 01:17:43,060 have to be first name and last name for example we can sort them by their birth 3508 01:17:43,060 --> 01:17:43,070 example we can sort them by their birth 3509 01:17:43,070 --> 01:17:43,600 example we can sort them by their birth date 3510 01:17:43,600 --> 01:17:43,610 date 3511 01:17:43,610 --> 01:17:46,870 date take a look so this is a valid query in 3512 01:17:46,870 --> 01:17:46,880 take a look so this is a valid query in 3513 01:17:46,880 --> 01:17:48,939 take a look so this is a valid query in my school but other database management 3514 01:17:48,939 --> 01:17:48,949 my school but other database management 3515 01:17:48,949 --> 01:17:50,709 my school but other database management system sometimes you yell at you when 3516 01:17:50,709 --> 01:17:50,719 system sometimes you yell at you when 3517 01:17:50,719 --> 01:17:52,840 system sometimes you yell at you when you write a query like this now we can 3518 01:17:52,840 --> 01:17:52,850 you write a query like this now we can 3519 01:17:52,850 --> 01:17:55,630 you write a query like this now we can also sort data by an alias for example 3520 01:17:55,630 --> 01:17:55,640 also sort data by an alias for example 3521 01:17:55,640 --> 01:17:58,780 also sort data by an alias for example here in our select clause let's add the 3522 01:17:58,780 --> 01:17:58,790 here in our select clause let's add the 3523 01:17:58,790 --> 01:18:02,200 here in our select clause let's add the number 10 and give it an alias as let's 3524 01:18:02,200 --> 01:18:02,210 number 10 and give it an alias as let's 3525 01:18:02,210 --> 01:18:04,630 number 10 and give it an alias as let's say points so points is not a valid 3526 01:18:04,630 --> 01:18:04,640 say points so points is not a valid 3527 01:18:04,640 --> 01:18:06,790 say points so points is not a valid column in this table it's simply an 3528 01:18:06,790 --> 01:18:06,800 column in this table it's simply an 3529 01:18:06,800 --> 01:18:09,040 column in this table it's simply an alias for an expression in this case a 3530 01:18:09,040 --> 01:18:09,050 alias for an expression in this case a 3531 01:18:09,050 --> 01:18:11,229 alias for an expression in this case a simple number now here we could have a 3532 01:18:11,229 --> 01:18:11,239 simple number now here we could have a 3533 01:18:11,239 --> 01:18:13,870 simple number now here we could have a complex mathematical expression it 3534 01:18:13,870 --> 01:18:13,880 complex mathematical expression it 3535 01:18:13,880 --> 01:18:16,240 complex mathematical expression it doesn't really matter we can still sort 3536 01:18:16,240 --> 01:18:16,250 doesn't really matter we can still sort 3537 01:18:16,250 --> 01:18:18,820 doesn't really matter we can still sort data by an alias so we can order by 3538 01:18:18,820 --> 01:18:18,830 data by an alias so we can order by 3539 01:18:18,830 --> 01:18:23,439 data by an alias so we can order by points and then first name once again 3540 01:18:23,439 --> 01:18:23,449 points and then first name once again 3541 01:18:23,449 --> 01:18:25,510 points and then first name once again this is a valid query from my skills 3542 01:18:25,510 --> 01:18:25,520 this is a valid query from my skills 3543 01:18:25,520 --> 01:18:27,939 this is a valid query from my skills point of view now one last thing before 3544 01:18:27,939 --> 01:18:27,949 point of view now one last thing before 3545 01:18:27,949 --> 01:18:29,890 point of view now one last thing before we finish this tutorial I've seen some 3546 01:18:29,890 --> 01:18:29,900 we finish this tutorial I've seen some 3547 01:18:29,900 --> 01:18:31,390 we finish this tutorial I've seen some tutorials that teach you how to sort 3548 01:18:31,390 --> 01:18:31,400 tutorials that teach you how to sort 3549 01:18:31,400 --> 01:18:33,729 tutorials that teach you how to sort data by column positions for example 3550 01:18:33,729 --> 01:18:33,739 data by column positions for example 3551 01:18:33,739 --> 01:18:36,430 data by column positions for example here we can order by one and two and 3552 01:18:36,430 --> 01:18:36,440 here we can order by one and two and 3553 01:18:36,440 --> 01:18:39,160 here we can order by one and two and that basically means sorted data by the 3554 01:18:39,160 --> 01:18:39,170 that basically means sorted data by the 3555 01:18:39,170 --> 01:18:41,680 that basically means sorted data by the first name and then the last name so 3556 01:18:41,680 --> 01:18:41,690 first name and then the last name so 3557 01:18:41,690 --> 01:18:44,530 first name and then the last name so these are the order of these columns if 3558 01:18:44,530 --> 01:18:44,540 these are the order of these columns if 3559 01:18:44,540 --> 01:18:46,660 these are the order of these columns if you execute this query you can see that 3560 01:18:46,660 --> 01:18:46,670 you execute this query you can see that 3561 01:18:46,670 --> 01:18:48,310 you execute this query you can see that our customers are sorted by their first 3562 01:18:48,310 --> 01:18:48,320 our customers are sorted by their first 3563 01:18:48,320 --> 01:18:49,459 our customers are sorted by their first name and then 3564 01:18:49,459 --> 01:18:49,469 name and then 3565 01:18:49,469 --> 01:18:52,009 name and then named wireless approach works it's 3566 01:18:52,009 --> 01:18:52,019 named wireless approach works it's 3567 01:18:52,019 --> 01:18:53,930 named wireless approach works it's something that you should avoid because 3568 01:18:53,930 --> 01:18:53,940 something that you should avoid because 3569 01:18:53,940 --> 01:18:55,489 something that you should avoid because if in the future you come back here and 3570 01:18:55,489 --> 01:18:55,499 if in the future you come back here and 3571 01:18:55,499 --> 01:18:58,430 if in the future you come back here and add a new column in front of the first 3572 01:18:58,430 --> 01:18:58,440 add a new column in front of the first 3573 01:18:58,440 --> 01:19:02,359 add a new column in front of the first name column let's say burst date now our 3574 01:19:02,359 --> 01:19:02,369 name column let's say burst date now our 3575 01:19:02,369 --> 01:19:04,129 name column let's say burst date now our customers are no longer sorted in the 3576 01:19:04,129 --> 01:19:04,139 customers are no longer sorted in the 3577 01:19:04,139 --> 01:19:07,129 customers are no longer sorted in the previous order so sorting data by column 3578 01:19:07,129 --> 01:19:07,139 previous order so sorting data by column 3579 01:19:07,139 --> 01:19:09,770 previous order so sorting data by column positions produces unexpected results 3580 01:19:09,770 --> 01:19:09,780 positions produces unexpected results 3581 01:19:09,780 --> 01:19:10,989 positions produces unexpected results and is something that you should avoid 3582 01:19:10,989 --> 01:19:10,999 and is something that you should avoid 3583 01:19:10,999 --> 01:19:14,120 and is something that you should avoid instead always sort by column names like 3584 01:19:14,120 --> 01:19:14,130 instead always sort by column names like 3585 01:19:14,130 --> 01:19:16,110 instead always sort by column names like first name 3586 01:19:16,110 --> 01:19:16,120 first name 3587 01:19:16,120 --> 01:19:19,370 first name you 3588 01:19:19,370 --> 01:19:19,380 3589 01:19:19,380 --> 01:19:21,540 all right here's your exercise for this 3590 01:19:21,540 --> 01:19:21,550 all right here's your exercise for this 3591 01:19:21,550 --> 01:19:23,760 all right here's your exercise for this tutorial in this database we have this 3592 01:19:23,760 --> 01:19:23,770 tutorial in this database we have this 3593 01:19:23,770 --> 01:19:25,979 tutorial in this database we have this table called order items where we can 3594 01:19:25,979 --> 01:19:25,989 table called order items where we can 3595 01:19:25,989 --> 01:19:28,530 table called order items where we can find the items for each order now I've 3596 01:19:28,530 --> 01:19:28,540 find the items for each order now I've 3597 01:19:28,540 --> 01:19:30,240 find the items for each order now I've written a query that you cannot see here 3598 01:19:30,240 --> 01:19:30,250 written a query that you cannot see here 3599 01:19:30,250 --> 01:19:31,590 written a query that you cannot see here because that's the solution to the 3600 01:19:31,590 --> 01:19:31,600 because that's the solution to the 3601 01:19:31,600 --> 01:19:33,870 because that's the solution to the exercise I'm gonna give you that query 3602 01:19:33,870 --> 01:19:33,880 exercise I'm gonna give you that query 3603 01:19:33,880 --> 01:19:37,229 exercise I'm gonna give you that query produces this result so we only have the 3604 01:19:37,229 --> 01:19:37,239 produces this result so we only have the 3605 01:19:37,239 --> 01:19:40,470 produces this result so we only have the items for the order with ID 2 and we 3606 01:19:40,470 --> 01:19:40,480 items for the order with ID 2 and we 3607 01:19:40,480 --> 01:19:42,900 items for the order with ID 2 and we have sorted these items based on the 3608 01:19:42,900 --> 01:19:42,910 have sorted these items based on the 3609 01:19:42,910 --> 01:19:45,300 have sorted these items based on the total price for each item so the total 3610 01:19:45,300 --> 01:19:45,310 total price for each item so the total 3611 01:19:45,310 --> 01:19:47,100 total price for each item so the total price for each item equals quantity 3612 01:19:47,100 --> 01:19:47,110 price for each item equals quantity 3613 01:19:47,110 --> 01:19:50,220 price for each item equals quantity times unit price in this case the total 3614 01:19:50,220 --> 01:19:50,230 times unit price in this case the total 3615 01:19:50,230 --> 01:19:54,840 times unit price in this case the total price for product 1 is just over $18 so 3616 01:19:54,840 --> 01:19:54,850 price for product 1 is just over $18 so 3617 01:19:54,850 --> 01:19:56,610 price for product 1 is just over $18 so go ahead and write the query to select 3618 01:19:56,610 --> 01:19:56,620 go ahead and write the query to select 3619 01:19:56,620 --> 01:19:59,700 go ahead and write the query to select all the items for order with ID 2 and 3620 01:19:59,700 --> 01:19:59,710 all the items for order with ID 2 and 3621 01:19:59,710 --> 01:20:01,830 all the items for order with ID 2 and sort them by their total price in 3622 01:20:01,830 --> 01:20:01,840 sort them by their total price in 3623 01:20:01,840 --> 01:20:04,180 sort them by their total price in descending order 3624 01:20:04,180 --> 01:20:04,190 descending order 3625 01:20:04,190 --> 01:20:07,950 descending order you 3626 01:20:07,950 --> 01:20:07,960 3627 01:20:07,960 --> 01:20:10,710 alright let's select everything from 3628 01:20:10,710 --> 01:20:10,720 alright let's select everything from 3629 01:20:10,720 --> 01:20:15,690 alright let's select everything from order items where order ID equals to 3630 01:20:15,690 --> 01:20:15,700 order items where order ID equals to 3631 01:20:15,700 --> 01:20:18,220 order items where order ID equals to that returns all the items for this 3632 01:20:18,220 --> 01:20:18,230 that returns all the items for this 3633 01:20:18,230 --> 01:20:20,680 that returns all the items for this order now I'm gonna make sure to sort 3634 01:20:20,680 --> 01:20:20,690 order now I'm gonna make sure to sort 3635 01:20:20,690 --> 01:20:24,340 order now I'm gonna make sure to sort them by their total price so here in 3636 01:20:24,340 --> 01:20:24,350 them by their total price so here in 3637 01:20:24,350 --> 01:20:26,070 them by their total price so here in order by clause we write an expression 3638 01:20:26,070 --> 01:20:26,080 order by clause we write an expression 3639 01:20:26,080 --> 01:20:30,760 order by clause we write an expression quantity times unit price this returns 3640 01:20:30,760 --> 01:20:30,770 quantity times unit price this returns 3641 01:20:30,770 --> 01:20:32,979 quantity times unit price this returns the total price for each item and then 3642 01:20:32,979 --> 01:20:32,989 the total price for each item and then 3643 01:20:32,989 --> 01:20:35,950 the total price for each item and then we add the descending argument here so 3644 01:20:35,950 --> 01:20:35,960 we add the descending argument here so 3645 01:20:35,960 --> 01:20:37,990 we add the descending argument here so once again the expression that we use in 3646 01:20:37,990 --> 01:20:38,000 once again the expression that we use in 3647 01:20:38,000 --> 01:20:39,940 once again the expression that we use in the order by Clause doesn't have to be a 3648 01:20:39,940 --> 01:20:39,950 the order by Clause doesn't have to be a 3649 01:20:39,950 --> 01:20:42,340 the order by Clause doesn't have to be a column name it can be an alias or an 3650 01:20:42,340 --> 01:20:42,350 column name it can be an alias or an 3651 01:20:42,350 --> 01:20:44,740 column name it can be an alias or an arithmetic expression like this let's go 3652 01:20:44,740 --> 01:20:44,750 arithmetic expression like this let's go 3653 01:20:44,750 --> 01:20:47,410 arithmetic expression like this let's go ahead and execute this query this is 3654 01:20:47,410 --> 01:20:47,420 ahead and execute this query this is 3655 01:20:47,420 --> 01:20:49,660 ahead and execute this query this is what we get now for clarity I would like 3656 01:20:49,660 --> 01:20:49,670 what we get now for clarity I would like 3657 01:20:49,670 --> 01:20:52,570 what we get now for clarity I would like to add another column and the result so 3658 01:20:52,570 --> 01:20:52,580 to add another column and the result so 3659 01:20:52,580 --> 01:20:56,979 to add another column and the result so let's say quantity times unit underline 3660 01:20:56,979 --> 01:20:56,989 let's say quantity times unit underline 3661 01:20:56,989 --> 01:20:59,680 let's say quantity times unit underline price but give it an alias like total 3662 01:20:59,680 --> 01:20:59,690 price but give it an alias like total 3663 01:20:59,690 --> 01:21:03,610 price but give it an alias like total price let's execute the query we can 3664 01:21:03,610 --> 01:21:03,620 price let's execute the query we can 3665 01:21:03,620 --> 01:21:05,979 price let's execute the query we can clearly see that this data is sorted by 3666 01:21:05,979 --> 01:21:05,989 clearly see that this data is sorted by 3667 01:21:05,989 --> 01:21:07,750 clearly see that this data is sorted by the total price in descending order 3668 01:21:07,750 --> 01:21:07,760 the total price in descending order 3669 01:21:07,760 --> 01:21:10,750 the total price in descending order however there is a bit of duplication in 3670 01:21:10,750 --> 01:21:10,760 however there is a bit of duplication in 3671 01:21:10,760 --> 01:21:12,340 however there is a bit of duplication in our query we have repeated this 3672 01:21:12,340 --> 01:21:12,350 our query we have repeated this 3673 01:21:12,350 --> 01:21:15,100 our query we have repeated this expression in two places so now we can 3674 01:21:15,100 --> 01:21:15,110 expression in two places so now we can 3675 01:21:15,110 --> 01:21:17,800 expression in two places so now we can simplify our order by clause by using an 3676 01:21:17,800 --> 01:21:17,810 simplify our order by clause by using an 3677 01:21:17,810 --> 01:21:21,400 simplify our order by clause by using an alias that is total price and we get the 3678 01:21:21,400 --> 01:21:21,410 alias that is total price and we get the 3679 01:21:21,410 --> 01:21:23,979 alias that is total price and we get the exact same result next I'm gonna show 3680 01:21:23,979 --> 01:21:23,989 exact same result next I'm gonna show 3681 01:21:23,989 --> 01:21:25,960 exact same result next I'm gonna show you how to limit the number of Records 3682 01:21:25,960 --> 01:21:25,970 you how to limit the number of Records 3683 01:21:25,970 --> 01:21:32,550 you how to limit the number of Records returned from your queries 3684 01:21:32,550 --> 01:21:32,560 3685 01:21:32,560 --> 01:21:34,899 in this tutorial I'm gonna show you how 3686 01:21:34,899 --> 01:21:34,909 in this tutorial I'm gonna show you how 3687 01:21:34,909 --> 01:21:36,910 in this tutorial I'm gonna show you how to limit the number of records returned 3688 01:21:36,910 --> 01:21:36,920 to limit the number of records returned 3689 01:21:36,920 --> 01:21:39,399 to limit the number of records returned from your query for example when we 3690 01:21:39,399 --> 01:21:39,409 from your query for example when we 3691 01:21:39,409 --> 01:21:41,470 from your query for example when we execute this query we get all the 3692 01:21:41,470 --> 01:21:41,480 execute this query we get all the 3693 01:21:41,480 --> 01:21:43,899 execute this query we get all the customers and the customer table so we 3694 01:21:43,899 --> 01:21:43,909 customers and the customer table so we 3695 01:21:43,909 --> 01:21:46,780 customers and the customer table so we have 10 customers here now what if you 3696 01:21:46,780 --> 01:21:46,790 have 10 customers here now what if you 3697 01:21:46,790 --> 01:21:48,879 have 10 customers here now what if you only want to get the first three 3698 01:21:48,879 --> 01:21:48,889 only want to get the first three 3699 01:21:48,889 --> 01:21:51,550 only want to get the first three customers that's where we use the limit 3700 01:21:51,550 --> 01:21:51,560 customers that's where we use the limit 3701 01:21:51,560 --> 01:21:52,899 customers that's where we use the limit clause let me show you 3702 01:21:52,899 --> 01:21:52,909 clause let me show you 3703 01:21:52,909 --> 01:21:57,669 clause let me show you so after from we type out limit 3 and 3704 01:21:57,669 --> 01:21:57,679 so after from we type out limit 3 and 3705 01:21:57,679 --> 01:22:00,370 so after from we type out limit 3 and this will return only the first 3 3706 01:22:00,370 --> 01:22:00,380 this will return only the first 3 3707 01:22:00,380 --> 01:22:03,100 this will return only the first 3 customers now if the argument that we 3708 01:22:03,100 --> 01:22:03,110 customers now if the argument that we 3709 01:22:03,110 --> 01:22:05,260 customers now if the argument that we pass here is greater than the number of 3710 01:22:05,260 --> 01:22:05,270 pass here is greater than the number of 3711 01:22:05,270 --> 01:22:07,689 pass here is greater than the number of records other query produces we'll get 3712 01:22:07,689 --> 01:22:07,699 records other query produces we'll get 3713 01:22:07,699 --> 01:22:09,820 records other query produces we'll get all the records in the query result for 3714 01:22:09,820 --> 01:22:09,830 all the records in the query result for 3715 01:22:09,830 --> 01:22:13,089 all the records in the query result for example if I pass 300 here obviously we 3716 01:22:13,089 --> 01:22:13,099 example if I pass 300 here obviously we 3717 01:22:13,099 --> 01:22:15,070 example if I pass 300 here obviously we don't have 300 customers in this table 3718 01:22:15,070 --> 01:22:15,080 don't have 300 customers in this table 3719 01:22:15,080 --> 01:22:17,890 don't have 300 customers in this table so when we execute this query we'll get 3720 01:22:17,890 --> 01:22:17,900 so when we execute this query we'll get 3721 01:22:17,900 --> 01:22:21,010 so when we execute this query we'll get all the 10 customers in this table so 3722 01:22:21,010 --> 01:22:21,020 all the 10 customers in this table so 3723 01:22:21,020 --> 01:22:24,459 all the 10 customers in this table so this is how the limit Clause works now 3724 01:22:24,459 --> 01:22:24,469 this is how the limit Clause works now 3725 01:22:24,469 --> 01:22:27,310 this is how the limit Clause works now here we can optionally supply an offset 3726 01:22:27,310 --> 01:22:27,320 here we can optionally supply an offset 3727 01:22:27,320 --> 01:22:29,080 here we can optionally supply an offset and this is very useful in situations 3728 01:22:29,080 --> 01:22:29,090 and this is very useful in situations 3729 01:22:29,090 --> 01:22:32,080 and this is very useful in situations where we want to paginate the data for 3730 01:22:32,080 --> 01:22:32,090 where we want to paginate the data for 3731 01:22:32,090 --> 01:22:33,760 where we want to paginate the data for example let's say we have a website and 3732 01:22:33,760 --> 01:22:33,770 example let's say we have a website and 3733 01:22:33,770 --> 01:22:36,010 example let's say we have a website and on this website we have a web page for 3734 01:22:36,010 --> 01:22:36,020 on this website we have a web page for 3735 01:22:36,020 --> 01:22:38,050 on this website we have a web page for the user to see all the customers in a 3736 01:22:38,050 --> 01:22:38,060 the user to see all the customers in a 3737 01:22:38,060 --> 01:22:40,180 the user to see all the customers in a database now for simplicity let's 3738 01:22:40,180 --> 01:22:40,190 database now for simplicity let's 3739 01:22:40,190 --> 01:22:42,070 database now for simplicity let's imagine you want to show only three 3740 01:22:42,070 --> 01:22:42,080 imagine you want to show only three 3741 01:22:42,080 --> 01:22:45,129 imagine you want to show only three customers per page so what are the 3742 01:22:45,129 --> 01:22:45,139 customers per page so what are the 3743 01:22:45,139 --> 01:22:46,870 customers per page so what are the customers that we're gonna have on page 3744 01:22:46,870 --> 01:22:46,880 customers that we're gonna have on page 3745 01:22:46,880 --> 01:22:51,430 customers that we're gonna have on page 1 we're gonna have customers 1 2 3 on 3746 01:22:51,430 --> 01:22:51,440 1 we're gonna have customers 1 2 3 on 3747 01:22:51,440 --> 01:22:54,910 1 we're gonna have customers 1 2 3 on page 2 we're gonna have customers 4 5 6 3748 01:22:54,910 --> 01:22:54,920 page 2 we're gonna have customers 4 5 6 3749 01:22:54,920 --> 01:22:57,550 page 2 we're gonna have customers 4 5 6 and on page 3 we're gonna have customers 3750 01:22:57,550 --> 01:22:57,560 and on page 3 we're gonna have customers 3751 01:22:57,560 --> 01:23:01,240 and on page 3 we're gonna have customers 7 8 9 now let's say we want to write a 3752 01:23:01,240 --> 01:23:01,250 7 8 9 now let's say we want to write a 3753 01:23:01,250 --> 01:23:03,490 7 8 9 now let's say we want to write a query to retrieve the customers on page 3754 01:23:03,490 --> 01:23:03,500 query to retrieve the customers on page 3755 01:23:03,500 --> 01:23:06,760 query to retrieve the customers on page 3 how can we do that well we want to 3756 01:23:06,760 --> 01:23:06,770 3 how can we do that well we want to 3757 01:23:06,770 --> 01:23:10,540 3 how can we do that well we want to skip the first 6 records and then pick 3 3758 01:23:10,540 --> 01:23:10,550 skip the first 6 records and then pick 3 3759 01:23:10,550 --> 01:23:12,910 skip the first 6 records and then pick 3 records right so we change our limit 3760 01:23:12,910 --> 01:23:12,920 records right so we change our limit 3761 01:23:12,920 --> 01:23:16,000 records right so we change our limit clause to something like this limit 6 & 3762 01:23:16,000 --> 01:23:16,010 clause to something like this limit 6 & 3763 01:23:16,010 --> 01:23:17,500 clause to something like this limit 6 & 3 3764 01:23:17,500 --> 01:23:17,510 3 3765 01:23:17,510 --> 01:23:20,260 3 so six is what we call an offset and 3766 01:23:20,260 --> 01:23:20,270 so six is what we call an offset and 3767 01:23:20,270 --> 01:23:22,780 so six is what we call an offset and that basically tells MySQL to skip the 3768 01:23:22,780 --> 01:23:22,790 that basically tells MySQL to skip the 3769 01:23:22,790 --> 01:23:26,110 that basically tells MySQL to skip the first six records and then pick three 3770 01:23:26,110 --> 01:23:26,120 first six records and then pick three 3771 01:23:26,120 --> 01:23:29,350 first six records and then pick three records let's execute this query all 3772 01:23:29,350 --> 01:23:29,360 records let's execute this query all 3773 01:23:29,360 --> 01:23:33,400 records let's execute this query all right now we get customers seven eight 3774 01:23:33,400 --> 01:23:33,410 right now we get customers seven eight 3775 01:23:33,410 --> 01:23:35,299 right now we get customers seven eight and nine 3776 01:23:35,299 --> 01:23:35,309 and nine 3777 01:23:35,309 --> 01:23:38,589 and nine you 3778 01:23:38,589 --> 01:23:38,599 3779 01:23:38,599 --> 01:23:41,240 now for your exercise I want you to get 3780 01:23:41,240 --> 01:23:41,250 now for your exercise I want you to get 3781 01:23:41,250 --> 01:23:44,510 now for your exercise I want you to get the top three loyal customers these are 3782 01:23:44,510 --> 01:23:44,520 the top three loyal customers these are 3783 01:23:44,520 --> 01:23:46,160 the top three loyal customers these are the customers that have more points than 3784 01:23:46,160 --> 01:23:46,170 the customers that have more points than 3785 01:23:46,170 --> 01:23:48,240 the customers that have more points than everyone else 3786 01:23:48,240 --> 01:23:48,250 everyone else 3787 01:23:48,250 --> 01:23:51,600 everyone else you 3788 01:23:51,600 --> 01:23:51,610 3789 01:23:51,610 --> 01:23:54,100 all right first we select everything 3790 01:23:54,100 --> 01:23:54,110 all right first we select everything 3791 01:23:54,110 --> 01:23:57,370 all right first we select everything from the customers table now we need to 3792 01:23:57,370 --> 01:23:57,380 from the customers table now we need to 3793 01:23:57,380 --> 01:24:00,330 from the customers table now we need to order these customers by their points in 3794 01:24:00,330 --> 01:24:00,340 order these customers by their points in 3795 01:24:00,340 --> 01:24:03,490 order these customers by their points in descending order so if you look at the 3796 01:24:03,490 --> 01:24:03,500 descending order so if you look at the 3797 01:24:03,500 --> 01:24:05,710 descending order so if you look at the query result you can see that customers 3798 01:24:05,710 --> 01:24:05,720 query result you can see that customers 3799 01:24:05,720 --> 01:24:08,470 query result you can see that customers are sorted by their loyalty so the most 3800 01:24:08,470 --> 01:24:08,480 are sorted by their loyalty so the most 3801 01:24:08,480 --> 01:24:11,260 are sorted by their loyalty so the most loyal customers come first now we want 3802 01:24:11,260 --> 01:24:11,270 loyal customers come first now we want 3803 01:24:11,270 --> 01:24:14,080 loyal customers come first now we want to pick only the first three customers 3804 01:24:14,080 --> 01:24:14,090 to pick only the first three customers 3805 01:24:14,090 --> 01:24:18,040 to pick only the first three customers and that's where we use the limit clause 3806 01:24:18,040 --> 01:24:18,050 and that's where we use the limit clause 3807 01:24:18,050 --> 01:24:22,290 and that's where we use the limit clause so limit 3 let's execute this query and 3808 01:24:22,290 --> 01:24:22,300 so limit 3 let's execute this query and 3809 01:24:22,300 --> 01:24:25,660 so limit 3 let's execute this query and these are the most loyal customers 3810 01:24:25,660 --> 01:24:25,670 these are the most loyal customers 3811 01:24:25,670 --> 01:24:30,520 these are the most loyal customers customers with IDs 5 6 & 3 now here's 3812 01:24:30,520 --> 01:24:30,530 customers with IDs 5 6 & 3 now here's 3813 01:24:30,530 --> 01:24:31,870 customers with IDs 5 6 & 3 now here's one thing I want you to remember and 3814 01:24:31,870 --> 01:24:31,880 one thing I want you to remember and 3815 01:24:31,880 --> 01:24:34,330 one thing I want you to remember and that is the order of the limit clause 3816 01:24:34,330 --> 01:24:34,340 that is the order of the limit clause 3817 01:24:34,340 --> 01:24:36,760 that is the order of the limit clause the limit clause should always come at 3818 01:24:36,760 --> 01:24:36,770 the limit clause should always come at 3819 01:24:36,770 --> 01:24:39,490 the limit clause should always come at the end so first we have a select clause 3820 01:24:39,490 --> 01:24:39,500 the end so first we have a select clause 3821 01:24:39,500 --> 01:24:42,580 the end so first we have a select clause then we have from optionally we can have 3822 01:24:42,580 --> 01:24:42,590 then we have from optionally we can have 3823 01:24:42,590 --> 01:24:45,760 then we have from optionally we can have where followed by order by and finally 3824 01:24:45,760 --> 01:24:45,770 where followed by order by and finally 3825 01:24:45,770 --> 01:24:48,640 where followed by order by and finally limit the order of these clauses matters 3826 01:24:48,640 --> 01:24:48,650 limit the order of these clauses matters 3827 01:24:48,650 --> 01:24:50,650 limit the order of these clauses matters if you change the order my sequel is 3828 01:24:50,650 --> 01:24:50,660 if you change the order my sequel is 3829 01:24:50,660 --> 01:24:52,690 if you change the order my sequel is gonna yell at you so pay attention to 3830 01:24:52,690 --> 01:24:52,700 gonna yell at you so pay attention to 3831 01:24:52,700 --> 01:24:59,350 gonna yell at you so pay attention to the order when writing your queries 3832 01:24:59,350 --> 01:24:59,360 3833 01:24:59,360 --> 01:25:01,880 so far we have only selected columns 3834 01:25:01,880 --> 01:25:01,890 so far we have only selected columns 3835 01:25:01,890 --> 01:25:03,920 so far we have only selected columns from a single table but in the real 3836 01:25:03,920 --> 01:25:03,930 from a single table but in the real 3837 01:25:03,930 --> 01:25:05,930 from a single table but in the real world we quit often select columns from 3838 01:25:05,930 --> 01:25:05,940 world we quit often select columns from 3839 01:25:05,940 --> 01:25:07,760 world we quit often select columns from multiple tables and that's what I'm 3840 01:25:07,760 --> 01:25:07,770 multiple tables and that's what I'm 3841 01:25:07,770 --> 01:25:09,140 multiple tables and that's what I'm gonna show you over the next few 3842 01:25:09,140 --> 01:25:09,150 gonna show you over the next few 3843 01:25:09,150 --> 01:25:12,080 gonna show you over the next few tutorials so on the left side if you 3844 01:25:12,080 --> 01:25:12,090 tutorials so on the left side if you 3845 01:25:12,090 --> 01:25:14,450 tutorials so on the left side if you look at our orders table let's select 3846 01:25:14,450 --> 01:25:14,460 look at our orders table let's select 3847 01:25:14,460 --> 01:25:17,090 look at our orders table let's select all the data here in this table we're 3848 01:25:17,090 --> 01:25:17,100 all the data here in this table we're 3849 01:25:17,100 --> 01:25:19,610 all the data here in this table we're using the customer ID column to identify 3850 01:25:19,610 --> 01:25:19,620 using the customer ID column to identify 3851 01:25:19,620 --> 01:25:22,070 using the customer ID column to identify the customer that has placed each order 3852 01:25:22,070 --> 01:25:22,080 the customer that has placed each order 3853 01:25:22,080 --> 01:25:24,620 the customer that has placed each order now as I told you before we don't store 3854 01:25:24,620 --> 01:25:24,630 now as I told you before we don't store 3855 01:25:24,630 --> 01:25:26,450 now as I told you before we don't store customers information here like their 3856 01:25:26,450 --> 01:25:26,460 customers information here like their 3857 01:25:26,460 --> 01:25:28,580 customers information here like their phone number their email their address 3858 01:25:28,580 --> 01:25:28,590 phone number their email their address 3859 01:25:28,590 --> 01:25:30,710 phone number their email their address because this information can change in 3860 01:25:30,710 --> 01:25:30,720 because this information can change in 3861 01:25:30,720 --> 01:25:32,990 because this information can change in the future and if a given customer has 3862 01:25:32,990 --> 01:25:33,000 the future and if a given customer has 3863 01:25:33,000 --> 01:25:34,820 the future and if a given customer has placed multiple orders then we'll have 3864 01:25:34,820 --> 01:25:34,830 placed multiple orders then we'll have 3865 01:25:34,830 --> 01:25:36,890 placed multiple orders then we'll have to come back and change multiple records 3866 01:25:36,890 --> 01:25:36,900 to come back and change multiple records 3867 01:25:36,900 --> 01:25:38,840 to come back and change multiple records we don't want to do that that's why we 3868 01:25:38,840 --> 01:25:38,850 we don't want to do that that's why we 3869 01:25:38,850 --> 01:25:41,150 we don't want to do that that's why we have separate tables for customers and 3870 01:25:41,150 --> 01:25:41,160 have separate tables for customers and 3871 01:25:41,160 --> 01:25:43,730 have separate tables for customers and orders now in this tutorial I'm gonna 3872 01:25:43,730 --> 01:25:43,740 orders now in this tutorial I'm gonna 3873 01:25:43,740 --> 01:25:45,920 orders now in this tutorial I'm gonna show you how to select the orders in the 3874 01:25:45,920 --> 01:25:45,930 show you how to select the orders in the 3875 01:25:45,930 --> 01:25:48,110 show you how to select the orders in the orders table but instead of showing the 3876 01:25:48,110 --> 01:25:48,120 orders table but instead of showing the 3877 01:25:48,120 --> 01:25:50,510 orders table but instead of showing the customer ID show the full name for each 3878 01:25:50,510 --> 01:25:50,520 customer ID show the full name for each 3879 01:25:50,520 --> 01:25:52,880 customer ID show the full name for each customer so let's go back to our query 3880 01:25:52,880 --> 01:25:52,890 customer so let's go back to our query 3881 01:25:52,890 --> 01:25:56,870 customer so let's go back to our query window alright so we want to select 3882 01:25:56,870 --> 01:25:56,880 window alright so we want to select 3883 01:25:56,880 --> 01:25:59,270 window alright so we want to select everything from the orders table now we 3884 01:25:59,270 --> 01:25:59,280 everything from the orders table now we 3885 01:25:59,280 --> 01:26:01,040 everything from the orders table now we should combine the columns in this table 3886 01:26:01,040 --> 01:26:01,050 should combine the columns in this table 3887 01:26:01,050 --> 01:26:03,130 should combine the columns in this table with the columns in the customers table 3888 01:26:03,130 --> 01:26:03,140 with the columns in the customers table 3889 01:26:03,140 --> 01:26:06,610 with the columns in the customers table that is where we use the join keyword 3890 01:26:06,610 --> 01:26:06,620 that is where we use the join keyword 3891 01:26:06,620 --> 01:26:09,350 that is where we use the join keyword now here we can optionally type inner 3892 01:26:09,350 --> 01:26:09,360 now here we can optionally type inner 3893 01:26:09,360 --> 01:26:11,570 now here we can optionally type inner join because in sequel we have two types 3894 01:26:11,570 --> 01:26:11,580 join because in sequel we have two types 3895 01:26:11,580 --> 01:26:14,600 join because in sequel we have two types of join inner join and outer join we 3896 01:26:14,600 --> 01:26:14,610 of join inner join and outer join we 3897 01:26:14,610 --> 01:26:15,980 of join inner join and outer join we look at outer joins later in this 3898 01:26:15,980 --> 01:26:15,990 look at outer joins later in this 3899 01:26:15,990 --> 01:26:18,230 look at outer joins later in this section so for now we're only using an 3900 01:26:18,230 --> 01:26:18,240 section so for now we're only using an 3901 01:26:18,240 --> 01:26:20,480 section so for now we're only using an inner join and this inner keyword is 3902 01:26:20,480 --> 01:26:20,490 inner join and this inner keyword is 3903 01:26:20,490 --> 01:26:22,130 inner join and this inner keyword is actually optional so we don't have to 3904 01:26:22,130 --> 01:26:22,140 actually optional so we don't have to 3905 01:26:22,140 --> 01:26:26,540 actually optional so we don't have to type it so you want to join the orders 3906 01:26:26,540 --> 01:26:26,550 type it so you want to join the orders 3907 01:26:26,550 --> 01:26:30,110 type it so you want to join the orders table with the customers table now on 3908 01:26:30,110 --> 01:26:30,120 table with the customers table now on 3909 01:26:30,120 --> 01:26:31,640 table with the customers table now on what basis do we want to join these 3910 01:26:31,640 --> 01:26:31,650 what basis do we want to join these 3911 01:26:31,650 --> 01:26:34,610 what basis do we want to join these tables well here in the customers table 3912 01:26:34,610 --> 01:26:34,620 tables well here in the customers table 3913 01:26:34,620 --> 01:26:37,010 tables well here in the customers table we have this customer ID column so if 3914 01:26:37,010 --> 01:26:37,020 we have this customer ID column so if 3915 01:26:37,020 --> 01:26:38,450 we have this customer ID column so if you put these two tables next to each 3916 01:26:38,450 --> 01:26:38,460 you put these two tables next to each 3917 01:26:38,460 --> 01:26:40,310 you put these two tables next to each other we want to line up the records 3918 01:26:40,310 --> 01:26:40,320 other we want to line up the records 3919 01:26:40,320 --> 01:26:43,160 other we want to line up the records such that the customer IDs are equal 3920 01:26:43,160 --> 01:26:43,170 such that the customer IDs are equal 3921 01:26:43,170 --> 01:26:47,390 such that the customer IDs are equal that is where we use the on phrase so 3922 01:26:47,390 --> 01:26:47,400 that is where we use the on phrase so 3923 01:26:47,400 --> 01:26:50,330 that is where we use the on phrase so after on we type out a condition here is 3924 01:26:50,330 --> 01:26:50,340 after on we type out a condition here is 3925 01:26:50,340 --> 01:26:52,250 after on we type out a condition here is a condition we need to type out orders 3926 01:26:52,250 --> 01:26:52,260 a condition we need to type out orders 3927 01:26:52,260 --> 01:26:55,760 a condition we need to type out orders dot customer underlined ID should be 3928 01:26:55,760 --> 01:26:55,770 dot customer underlined ID should be 3929 01:26:55,770 --> 01:27:00,830 dot customer underlined ID should be equal to customers dot customer ID now 3930 01:27:00,830 --> 01:27:00,840 equal to customers dot customer ID now 3931 01:27:00,840 --> 01:27:02,750 equal to customers dot customer ID now this is getting outside of the screen so 3932 01:27:02,750 --> 01:27:02,760 this is getting outside of the screen so 3933 01:27:02,760 --> 01:27:06,040 this is getting outside of the screen so let me break up this line that's better 3934 01:27:06,040 --> 01:27:06,050 let me break up this line that's better 3935 01:27:06,050 --> 01:27:09,140 let me break up this line that's better so with this query we're telling MySQL 3936 01:27:09,140 --> 01:27:09,150 so with this query we're telling MySQL 3937 01:27:09,150 --> 01:27:11,000 so with this query we're telling MySQL but hey whenever you're joining the 3938 01:27:11,000 --> 01:27:11,010 but hey whenever you're joining the 3939 01:27:11,010 --> 01:27:13,220 but hey whenever you're joining the orders table with the customers table 3940 01:27:13,220 --> 01:27:13,230 orders table with the customers table 3941 01:27:13,230 --> 01:27:16,160 orders table with the customers table make sure that the customer ID column in 3942 01:27:16,160 --> 01:27:16,170 make sure that the customer ID column in 3943 01:27:16,170 --> 01:27:19,820 make sure that the customer ID column in the orders table equals the customer ID 3944 01:27:19,820 --> 01:27:19,830 the orders table equals the customer ID 3945 01:27:19,830 --> 01:27:23,060 the orders table equals the customer ID column in the customers table now let's 3946 01:27:23,060 --> 01:27:23,070 column in the customers table now let's 3947 01:27:23,070 --> 01:27:28,379 column in the customers table now let's execute this query look at the result 3948 01:27:28,379 --> 01:27:28,389 3949 01:27:28,389 --> 01:27:30,270 since we are selecting everything here 3950 01:27:30,270 --> 01:27:30,280 since we are selecting everything here 3951 01:27:30,280 --> 01:27:32,580 since we are selecting everything here the first few columns are from the 3952 01:27:32,580 --> 01:27:32,590 the first few columns are from the 3953 01:27:32,590 --> 01:27:34,379 the first few columns are from the orders table because we have listed that 3954 01:27:34,379 --> 01:27:34,389 orders table because we have listed that 3955 01:27:34,389 --> 01:27:37,890 orders table because we have listed that first now after all the columns in the 3956 01:27:37,890 --> 01:27:37,900 first now after all the columns in the 3957 01:27:37,900 --> 01:27:40,590 first now after all the columns in the orders table we have the columns in a 3958 01:27:40,590 --> 01:27:40,600 orders table we have the columns in a 3959 01:27:40,600 --> 01:27:43,020 orders table we have the columns in a customer table so customer ID first name 3960 01:27:43,020 --> 01:27:43,030 customer table so customer ID first name 3961 01:27:43,030 --> 01:27:45,419 customer table so customer ID first name last name and so on now let's simplify 3962 01:27:45,419 --> 01:27:45,429 last name and so on now let's simplify 3963 01:27:45,429 --> 01:27:48,240 last name and so on now let's simplify the result set and select only order ID 3964 01:27:48,240 --> 01:27:48,250 the result set and select only order ID 3965 01:27:48,250 --> 01:27:51,510 the result set and select only order ID first name and last name so back to our 3966 01:27:51,510 --> 01:27:51,520 first name and last name so back to our 3967 01:27:51,520 --> 01:27:56,580 first name and last name so back to our query we select order ID first name and 3968 01:27:56,580 --> 01:27:56,590 query we select order ID first name and 3969 01:27:56,590 --> 01:28:00,090 query we select order ID first name and last name now let's execute the query 3970 01:28:00,090 --> 01:28:00,100 last name now let's execute the query 3971 01:28:00,100 --> 01:28:03,419 last name now let's execute the query that is better so next to each order ID 3972 01:28:03,419 --> 01:28:03,429 that is better so next to each order ID 3973 01:28:03,429 --> 01:28:05,310 that is better so next to each order ID we can see the name of the customer that 3974 01:28:05,310 --> 01:28:05,320 we can see the name of the customer that 3975 01:28:05,320 --> 01:28:07,740 we can see the name of the customer that placed that order now what if you want 3976 01:28:07,740 --> 01:28:07,750 placed that order now what if you want 3977 01:28:07,750 --> 01:28:10,100 placed that order now what if you want to display the customer ID here as well 3978 01:28:10,100 --> 01:28:10,110 to display the customer ID here as well 3979 01:28:10,110 --> 01:28:12,570 to display the customer ID here as well well let's put that here and see what 3980 01:28:12,570 --> 01:28:12,580 well let's put that here and see what 3981 01:28:12,580 --> 01:28:13,050 well let's put that here and see what happens 3982 01:28:13,050 --> 01:28:13,060 happens 3983 01:28:13,060 --> 01:28:17,040 happens customer ID execute the query we get an 3984 01:28:17,040 --> 01:28:17,050 customer ID execute the query we get an 3985 01:28:17,050 --> 01:28:18,540 customer ID execute the query we get an error so if you look at the output 3986 01:28:18,540 --> 01:28:18,550 error so if you look at the output 3987 01:28:18,550 --> 01:28:20,970 error so if you look at the output window down the bottom you should see an 3988 01:28:20,970 --> 01:28:20,980 window down the bottom you should see an 3989 01:28:20,980 --> 01:28:23,370 window down the bottom you should see an error saying column customer ID in the 3990 01:28:23,370 --> 01:28:23,380 error saying column customer ID in the 3991 01:28:23,380 --> 01:28:25,350 error saying column customer ID in the field list is ambiguous now 3992 01:28:25,350 --> 01:28:25,360 field list is ambiguous now 3993 01:28:25,360 --> 01:28:26,729 field list is ambiguous now unfortunately I cannot show you this 3994 01:28:26,729 --> 01:28:26,739 unfortunately I cannot show you this 3995 01:28:26,739 --> 01:28:28,709 unfortunately I cannot show you this error because the size of my recording 3996 01:28:28,709 --> 01:28:28,719 error because the size of my recording 3997 01:28:28,719 --> 01:28:31,080 error because the size of my recording window is smaller than MySQL workbench 3998 01:28:31,080 --> 01:28:31,090 window is smaller than MySQL workbench 3999 01:28:31,090 --> 01:28:33,899 window is smaller than MySQL workbench but that aside let me explain why we're 4000 01:28:33,899 --> 01:28:33,909 but that aside let me explain why we're 4001 01:28:33,909 --> 01:28:35,669 but that aside let me explain why we're getting this error because we have this 4002 01:28:35,669 --> 01:28:35,679 getting this error because we have this 4003 01:28:35,679 --> 01:28:38,220 getting this error because we have this customer ID column in both the orders 4004 01:28:38,220 --> 01:28:38,230 customer ID column in both the orders 4005 01:28:38,230 --> 01:28:41,729 customer ID column in both the orders and customers tables so MySQL is not 4006 01:28:41,729 --> 01:28:41,739 and customers tables so MySQL is not 4007 01:28:41,739 --> 01:28:43,830 and customers tables so MySQL is not sure which table do we want to select 4008 01:28:43,830 --> 01:28:43,840 sure which table do we want to select 4009 01:28:43,840 --> 01:28:46,080 sure which table do we want to select this column from that is why it's saying 4010 01:28:46,080 --> 01:28:46,090 this column from that is why it's saying 4011 01:28:46,090 --> 01:28:48,870 this column from that is why it's saying this column is ambiguous so we need to 4012 01:28:48,870 --> 01:28:48,880 this column is ambiguous so we need to 4013 01:28:48,880 --> 01:28:51,600 this column is ambiguous so we need to qualify this column by prefixing it with 4014 01:28:51,600 --> 01:28:51,610 qualify this column by prefixing it with 4015 01:28:51,610 --> 01:28:54,479 qualify this column by prefixing it with a table name we can either pick it from 4016 01:28:54,479 --> 01:28:54,489 a table name we can either pick it from 4017 01:28:54,489 --> 01:28:57,060 a table name we can either pick it from the orders table or the customers table 4018 01:28:57,060 --> 01:28:57,070 the orders table or the customers table 4019 01:28:57,070 --> 01:28:58,680 the orders table or the customers table it doesn't really matter because the 4020 01:28:58,680 --> 01:28:58,690 it doesn't really matter because the 4021 01:28:58,690 --> 01:29:03,510 it doesn't really matter because the values are equal right so in situations 4022 01:29:03,510 --> 01:29:03,520 values are equal right so in situations 4023 01:29:03,520 --> 01:29:05,490 values are equal right so in situations where you have the same column in 4024 01:29:05,490 --> 01:29:05,500 where you have the same column in 4025 01:29:05,500 --> 01:29:07,950 where you have the same column in multiple tables you need to qualify them 4026 01:29:07,950 --> 01:29:07,960 multiple tables you need to qualify them 4027 01:29:07,960 --> 01:29:10,470 multiple tables you need to qualify them by prefixing them with the name of their 4028 01:29:10,470 --> 01:29:10,480 by prefixing them with the name of their 4029 01:29:10,480 --> 01:29:12,930 by prefixing them with the name of their table okay now almost execute the query 4030 01:29:12,930 --> 01:29:12,940 table okay now almost execute the query 4031 01:29:12,940 --> 01:29:15,479 table okay now almost execute the query one more time so there you go we have 4032 01:29:15,479 --> 01:29:15,489 one more time so there you go we have 4033 01:29:15,489 --> 01:29:17,820 one more time so there you go we have order ID customer ID and a full name 4034 01:29:17,820 --> 01:29:17,830 order ID customer ID and a full name 4035 01:29:17,830 --> 01:29:20,399 order ID customer ID and a full name beautiful now one more thing before we 4036 01:29:20,399 --> 01:29:20,409 beautiful now one more thing before we 4037 01:29:20,409 --> 01:29:22,350 beautiful now one more thing before we finish this tutorial if you pay close 4038 01:29:22,350 --> 01:29:22,360 finish this tutorial if you pay close 4039 01:29:22,360 --> 01:29:24,149 finish this tutorial if you pay close attention we have repeated the word 4040 01:29:24,149 --> 01:29:24,159 attention we have repeated the word 4041 01:29:24,159 --> 01:29:27,090 attention we have repeated the word orders in multiple places we have it 4042 01:29:27,090 --> 01:29:27,100 orders in multiple places we have it 4043 01:29:27,100 --> 01:29:29,459 orders in multiple places we have it here as well as in the joint condition 4044 01:29:29,459 --> 01:29:29,469 here as well as in the joint condition 4045 01:29:29,469 --> 01:29:31,470 here as well as in the joint condition the same is true about the customers 4046 01:29:31,470 --> 01:29:31,480 the same is true about the customers 4047 01:29:31,480 --> 01:29:34,859 the same is true about the customers table we have repeated that here we can 4048 01:29:34,859 --> 01:29:34,869 table we have repeated that here we can 4049 01:29:34,869 --> 01:29:36,570 table we have repeated that here we can get rid of this repetition and make our 4050 01:29:36,570 --> 01:29:36,580 get rid of this repetition and make our 4051 01:29:36,580 --> 01:29:40,050 get rid of this repetition and make our code simpler by using an alias so right 4052 01:29:40,050 --> 01:29:40,060 code simpler by using an alias so right 4053 01:29:40,060 --> 01:29:42,209 code simpler by using an alias so right after each table we can give it an 4054 01:29:42,209 --> 01:29:42,219 after each table we can give it an 4055 01:29:42,219 --> 01:29:45,719 after each table we can give it an alias Oh as in short for orders so by 4056 01:29:45,719 --> 01:29:45,729 alias Oh as in short for orders so by 4057 01:29:45,729 --> 01:29:47,899 alias Oh as in short for orders so by convention we abbreviate the tables name 4058 01:29:47,899 --> 01:29:47,909 convention we abbreviate the tables name 4059 01:29:47,909 --> 01:29:51,270 convention we abbreviate the tables name now wherever we have orders we should 4060 01:29:51,270 --> 01:29:51,280 now wherever we have orders we should 4061 01:29:51,280 --> 01:29:54,270 now wherever we have orders we should replace that with O so here in the joint 4062 01:29:54,270 --> 01:29:54,280 replace that with O so here in the joint 4063 01:29:54,280 --> 01:29:56,810 replace that with O so here in the joint condition we replace orders with O and 4064 01:29:56,810 --> 01:29:56,820 condition we replace orders with O and 4065 01:29:56,820 --> 01:30:00,439 condition we replace orders with O and also one more time and the Select Clause 4066 01:30:00,439 --> 01:30:00,449 also one more time and the Select Clause 4067 01:30:00,449 --> 01:30:01,859 also one more time and the Select Clause there you go 4068 01:30:01,859 --> 01:30:01,869 there you go 4069 01:30:01,869 --> 01:30:03,899 there you go we can also apply an alias for the 4070 01:30:03,899 --> 01:30:03,909 we can also apply an alias for the 4071 01:30:03,909 --> 01:30:06,660 we can also apply an alias for the customers table we've got it see and 4072 01:30:06,660 --> 01:30:06,670 customers table we've got it see and 4073 01:30:06,670 --> 01:30:09,330 customers table we've got it see and then we simplify our joint condition 4074 01:30:09,330 --> 01:30:09,340 then we simplify our joint condition 4075 01:30:09,340 --> 01:30:12,089 then we simplify our joint condition like this so this is how we can join 4076 01:30:12,089 --> 01:30:12,099 like this so this is how we can join 4077 01:30:12,099 --> 01:30:18,399 like this so this is how we can join columns from multiple tables 4078 01:30:18,399 --> 01:30:18,409 4079 01:30:18,409 --> 01:30:21,350 now for your exercise I want you to look 4080 01:30:21,350 --> 01:30:21,360 now for your exercise I want you to look 4081 01:30:21,360 --> 01:30:25,790 now for your exercise I want you to look at the order items table so in this 4082 01:30:25,790 --> 01:30:25,800 at the order items table so in this 4083 01:30:25,800 --> 01:30:27,500 at the order items table so in this table we have these columns or their ID 4084 01:30:27,500 --> 01:30:27,510 table we have these columns or their ID 4085 01:30:27,510 --> 01:30:30,709 table we have these columns or their ID product ID quantity and unit price now I 4086 01:30:30,709 --> 01:30:30,719 product ID quantity and unit price now I 4087 01:30:30,719 --> 01:30:32,959 product ID quantity and unit price now I want you to write a query and join this 4088 01:30:32,959 --> 01:30:32,969 want you to write a query and join this 4089 01:30:32,969 --> 01:30:35,299 want you to write a query and join this table with the products table so for 4090 01:30:35,299 --> 01:30:35,309 table with the products table so for 4091 01:30:35,309 --> 01:30:38,120 table with the products table so for each order return both the product ID as 4092 01:30:38,120 --> 01:30:38,130 each order return both the product ID as 4093 01:30:38,130 --> 01:30:40,009 each order return both the product ID as well as its name followed by the 4094 01:30:40,009 --> 01:30:40,019 well as its name followed by the 4095 01:30:40,019 --> 01:30:42,229 well as its name followed by the quantity and the unit price from the 4096 01:30:42,229 --> 01:30:42,239 quantity and the unit price from the 4097 01:30:42,239 --> 01:30:44,540 quantity and the unit price from the order items table and by the way make 4098 01:30:44,540 --> 01:30:44,550 order items table and by the way make 4099 01:30:44,550 --> 01:30:46,250 order items table and by the way make sure to use an alias to simplify your 4100 01:30:46,250 --> 01:30:46,260 sure to use an alias to simplify your 4101 01:30:46,260 --> 01:30:48,010 sure to use an alias to simplify your code 4102 01:30:48,010 --> 01:30:48,020 code 4103 01:30:48,020 --> 01:30:51,419 code you 4104 01:30:51,419 --> 01:30:51,429 4105 01:30:51,429 --> 01:30:54,160 alright first let's select everything 4106 01:30:54,160 --> 01:30:54,170 alright first let's select everything 4107 01:30:54,170 --> 01:30:58,780 alright first let's select everything from the older items table and then join 4108 01:30:58,780 --> 01:30:58,790 from the older items table and then join 4109 01:30:58,790 --> 01:31:02,290 from the older items table and then join it with the products table how are we 4110 01:31:02,290 --> 01:31:02,300 it with the products table how are we 4111 01:31:02,300 --> 01:31:06,070 it with the products table how are we gonna join these tables on order under 4112 01:31:06,070 --> 01:31:06,080 gonna join these tables on order under 4113 01:31:06,080 --> 01:31:08,680 gonna join these tables on order under line items dot well actually let's just 4114 01:31:08,680 --> 01:31:08,690 line items dot well actually let's just 4115 01:31:08,690 --> 01:31:10,930 line items dot well actually let's just keep this an alias right away so we use 4116 01:31:10,930 --> 01:31:10,940 keep this an alias right away so we use 4117 01:31:10,940 --> 01:31:14,020 keep this an alias right away so we use oh I as an abbreviation for order items 4118 01:31:14,020 --> 01:31:14,030 oh I as an abbreviation for order items 4119 01:31:14,030 --> 01:31:18,149 oh I as an abbreviation for order items and P has a short for products so oh I 4120 01:31:18,149 --> 01:31:18,159 and P has a short for products so oh I 4121 01:31:18,159 --> 01:31:22,990 and P has a short for products so oh I dot product ID should be equal to P or 4122 01:31:22,990 --> 01:31:23,000 dot product ID should be equal to P or 4123 01:31:23,000 --> 01:31:26,410 dot product ID should be equal to P or products dot product ID and by the way 4124 01:31:26,410 --> 01:31:26,420 products dot product ID and by the way 4125 01:31:26,420 --> 01:31:28,479 products dot product ID and by the way remember that when you give an alias to 4126 01:31:28,479 --> 01:31:28,489 remember that when you give an alias to 4127 01:31:28,489 --> 01:31:30,729 remember that when you give an alias to a table you have to use that alias 4128 01:31:30,729 --> 01:31:30,739 a table you have to use that alias 4129 01:31:30,739 --> 01:31:32,500 a table you have to use that alias everywhere else so here I cannot type 4130 01:31:32,500 --> 01:31:32,510 everywhere else so here I cannot type 4131 01:31:32,510 --> 01:31:35,080 everywhere else so here I cannot type out products my school is gonna yell at 4132 01:31:35,080 --> 01:31:35,090 out products my school is gonna yell at 4133 01:31:35,090 --> 01:31:38,080 out products my school is gonna yell at me so let's use the abbreviation alright 4134 01:31:38,080 --> 01:31:38,090 me so let's use the abbreviation alright 4135 01:31:38,090 --> 01:31:40,390 me so let's use the abbreviation alright this is how we join these tables let's 4136 01:31:40,390 --> 01:31:40,400 this is how we join these tables let's 4137 01:31:40,400 --> 01:31:42,629 this is how we join these tables let's execute this query up to this point 4138 01:31:42,629 --> 01:31:42,639 execute this query up to this point 4139 01:31:42,639 --> 01:31:45,939 execute this query up to this point alright so we see all the items from the 4140 01:31:45,939 --> 01:31:45,949 alright so we see all the items from the 4141 01:31:45,949 --> 01:31:48,100 alright so we see all the items from the order items table followed by the 4142 01:31:48,100 --> 01:31:48,110 order items table followed by the 4143 01:31:48,110 --> 01:31:51,640 order items table followed by the columns from the products table now we 4144 01:31:51,640 --> 01:31:51,650 columns from the products table now we 4145 01:31:51,650 --> 01:31:54,100 columns from the products table now we want to explicitly select a few columns 4146 01:31:54,100 --> 01:31:54,110 want to explicitly select a few columns 4147 01:31:54,110 --> 01:31:56,979 want to explicitly select a few columns here so from the order items table we 4148 01:31:56,979 --> 01:31:56,989 here so from the order items table we 4149 01:31:56,989 --> 01:32:00,760 here so from the order items table we want to select order under line ID well 4150 01:32:00,760 --> 01:32:00,770 want to select order under line ID well 4151 01:32:00,770 --> 01:32:02,500 want to select order under line ID well technically we don't have to prefix this 4152 01:32:02,500 --> 01:32:02,510 technically we don't have to prefix this 4153 01:32:02,510 --> 01:32:04,930 technically we don't have to prefix this with the table name because this column 4154 01:32:04,930 --> 01:32:04,940 with the table name because this column 4155 01:32:04,940 --> 01:32:07,030 with the table name because this column is not repeated in multiple places so 4156 01:32:07,030 --> 01:32:07,040 is not repeated in multiple places so 4157 01:32:07,040 --> 01:32:09,550 is not repeated in multiple places so it's not ambiguous so let's make the 4158 01:32:09,550 --> 01:32:09,560 it's not ambiguous so let's make the 4159 01:32:09,560 --> 01:32:12,310 it's not ambiguous so let's make the code shorter that's better now we want 4160 01:32:12,310 --> 01:32:12,320 code shorter that's better now we want 4161 01:32:12,320 --> 01:32:15,010 code shorter that's better now we want to select the product ID column but 4162 01:32:15,010 --> 01:32:15,020 to select the product ID column but 4163 01:32:15,020 --> 01:32:16,750 to select the product ID column but because this column exists in both 4164 01:32:16,750 --> 01:32:16,760 because this column exists in both 4165 01:32:16,760 --> 01:32:19,030 because this column exists in both tables you have to prefix it with a 4166 01:32:19,030 --> 01:32:19,040 tables you have to prefix it with a 4167 01:32:19,040 --> 01:32:20,379 tables you have to prefix it with a table link either 4168 01:32:20,379 --> 01:32:20,389 table link either 4169 01:32:20,389 --> 01:32:24,520 table link either oh I or P it doesn't really matter next 4170 01:32:24,520 --> 01:32:24,530 oh I or P it doesn't really matter next 4171 01:32:24,530 --> 01:32:26,950 oh I or P it doesn't really matter next we want to select quantity and finally 4172 01:32:26,950 --> 01:32:26,960 we want to select quantity and finally 4173 01:32:26,960 --> 01:32:30,490 we want to select quantity and finally unit price now actually here we have 4174 01:32:30,490 --> 01:32:30,500 unit price now actually here we have 4175 01:32:30,500 --> 01:32:33,459 unit price now actually here we have this unit price column in both tables so 4176 01:32:33,459 --> 01:32:33,469 this unit price column in both tables so 4177 01:32:33,469 --> 01:32:35,439 this unit price column in both tables so this is the unit price in order items 4178 01:32:35,439 --> 01:32:35,449 this is the unit price in order items 4179 01:32:35,449 --> 01:32:38,859 this is the unit price in order items table and this is the unit price in the 4180 01:32:38,859 --> 01:32:38,869 table and this is the unit price in the 4181 01:32:38,869 --> 01:32:40,780 table and this is the unit price in the products table now you might be curious 4182 01:32:40,780 --> 01:32:40,790 products table now you might be curious 4183 01:32:40,790 --> 01:32:42,520 products table now you might be curious why we have this economy in two places 4184 01:32:42,520 --> 01:32:42,530 why we have this economy in two places 4185 01:32:42,530 --> 01:32:45,430 why we have this economy in two places the reason for this is that the price of 4186 01:32:45,430 --> 01:32:45,440 the reason for this is that the price of 4187 01:32:45,440 --> 01:32:48,220 the reason for this is that the price of products can change so for each order 4188 01:32:48,220 --> 01:32:48,230 products can change so for each order 4189 01:32:48,230 --> 01:32:50,680 products can change so for each order item we want to have the price at the 4190 01:32:50,680 --> 01:32:50,690 item we want to have the price at the 4191 01:32:50,690 --> 01:32:53,260 item we want to have the price at the time the user or the customer place the 4192 01:32:53,260 --> 01:32:53,270 time the user or the customer place the 4193 01:32:53,270 --> 01:32:55,810 time the user or the customer place the order so this is a snapshot of the price 4194 01:32:55,810 --> 01:32:55,820 order so this is a snapshot of the price 4195 01:32:55,820 --> 01:32:58,570 order so this is a snapshot of the price at a given point in time the unit price 4196 01:32:58,570 --> 01:32:58,580 at a given point in time the unit price 4197 01:32:58,580 --> 01:33:00,270 at a given point in time the unit price that we have in the products table is 4198 01:33:00,270 --> 01:33:00,280 that we have in the products table is 4199 01:33:00,280 --> 01:33:03,700 that we have in the products table is the current price right now this is very 4200 01:33:03,700 --> 01:33:03,710 the current price right now this is very 4201 01:33:03,710 --> 01:33:04,779 the current price right now this is very important for reporting 4202 01:33:04,779 --> 01:33:04,789 important for reporting 4203 01:33:04,789 --> 01:33:06,549 important for reporting otherwise we cannot calculate the sales 4204 01:33:06,549 --> 01:33:06,559 otherwise we cannot calculate the sales 4205 01:33:06,559 --> 01:33:09,069 otherwise we cannot calculate the sales properly so because we have the unit 4206 01:33:09,069 --> 01:33:09,079 properly so because we have the unit 4207 01:33:09,079 --> 01:33:11,470 properly so because we have the unit price column in two places in this case 4208 01:33:11,470 --> 01:33:11,480 price column in two places in this case 4209 01:33:11,480 --> 01:33:13,060 price column in two places in this case we should pick it from the order items 4210 01:33:13,060 --> 01:33:13,070 we should pick it from the order items 4211 01:33:13,070 --> 01:33:15,490 we should pick it from the order items table because this is the price at the 4212 01:33:15,490 --> 01:33:15,500 table because this is the price at the 4213 01:33:15,500 --> 01:33:18,009 table because this is the price at the time of placing the order now let's 4214 01:33:18,009 --> 01:33:18,019 time of placing the order now let's 4215 01:33:18,019 --> 01:33:20,410 time of placing the order now let's execute the query so here's the final 4216 01:33:20,410 --> 01:33:20,420 execute the query so here's the final 4217 01:33:20,420 --> 01:33:26,250 execute the query so here's the final result 4218 01:33:26,250 --> 01:33:26,260 4219 01:33:26,260 --> 01:33:28,510 in the real world when you work as a 4220 01:33:28,510 --> 01:33:28,520 in the real world when you work as a 4221 01:33:28,520 --> 01:33:30,630 in the real world when you work as a developer or a database administrator 4222 01:33:30,630 --> 01:33:30,640 developer or a database administrator 4223 01:33:30,640 --> 01:33:32,980 developer or a database administrator quit often you will have to work with 4224 01:33:32,980 --> 01:33:32,990 quit often you will have to work with 4225 01:33:32,990 --> 01:33:35,530 quit often you will have to work with multiple databases in this tutorial I'm 4226 01:33:35,530 --> 01:33:35,540 multiple databases in this tutorial I'm 4227 01:33:35,540 --> 01:33:37,330 multiple databases in this tutorial I'm gonna show you how to combine columns 4228 01:33:37,330 --> 01:33:37,340 gonna show you how to combine columns 4229 01:33:37,340 --> 01:33:40,060 gonna show you how to combine columns from tables across multiple databases 4230 01:33:40,060 --> 01:33:40,070 from tables across multiple databases 4231 01:33:40,070 --> 01:33:42,490 from tables across multiple databases that's pretty easy so in the sequel 4232 01:33:42,490 --> 01:33:42,500 that's pretty easy so in the sequel 4233 01:33:42,500 --> 01:33:44,620 that's pretty easy so in the sequel store database we have these tables that 4234 01:33:44,620 --> 01:33:44,630 store database we have these tables that 4235 01:33:44,630 --> 01:33:47,050 store database we have these tables that you're fairly familiar with now imagine 4236 01:33:47,050 --> 01:33:47,060 you're fairly familiar with now imagine 4237 01:33:47,060 --> 01:33:50,320 you're fairly familiar with now imagine this products table was not here now if 4238 01:33:50,320 --> 01:33:50,330 this products table was not here now if 4239 01:33:50,330 --> 01:33:51,970 this products table was not here now if you look at the sequel inventory 4240 01:33:51,970 --> 01:33:51,980 you look at the sequel inventory 4241 01:33:51,980 --> 01:33:53,910 you look at the sequel inventory database you can see here we have 4242 01:33:53,910 --> 01:33:53,920 database you can see here we have 4243 01:33:53,920 --> 01:33:56,680 database you can see here we have another products table this products 4244 01:33:56,680 --> 01:33:56,690 another products table this products 4245 01:33:56,690 --> 01:33:58,900 another products table this products table is exactly the same as the 4246 01:33:58,900 --> 01:33:58,910 table is exactly the same as the 4247 01:33:58,910 --> 01:34:01,150 table is exactly the same as the products table that we have in a sequel 4248 01:34:01,150 --> 01:34:01,160 products table that we have in a sequel 4249 01:34:01,160 --> 01:34:02,710 products table that we have in a sequel store database so it has the same 4250 01:34:02,710 --> 01:34:02,720 store database so it has the same 4251 01:34:02,720 --> 01:34:05,140 store database so it has the same columns on the same data but technically 4252 01:34:05,140 --> 01:34:05,150 columns on the same data but technically 4253 01:34:05,150 --> 01:34:07,270 columns on the same data but technically this is not a good design you don't have 4254 01:34:07,270 --> 01:34:07,280 this is not a good design you don't have 4255 01:34:07,280 --> 01:34:09,670 this is not a good design you don't have the same table repeated in multiple 4256 01:34:09,670 --> 01:34:09,680 the same table repeated in multiple 4257 01:34:09,680 --> 01:34:11,830 the same table repeated in multiple places but for this demo let's just 4258 01:34:11,830 --> 01:34:11,840 places but for this demo let's just 4259 01:34:11,840 --> 01:34:13,690 places but for this demo let's just imagine that we don't have the products 4260 01:34:13,690 --> 01:34:13,700 imagine that we don't have the products 4261 01:34:13,700 --> 01:34:16,420 imagine that we don't have the products table here so we want to join the order 4262 01:34:16,420 --> 01:34:16,430 table here so we want to join the order 4263 01:34:16,430 --> 01:34:19,330 table here so we want to join the order items table with the products table in 4264 01:34:19,330 --> 01:34:19,340 items table with the products table in 4265 01:34:19,340 --> 01:34:21,910 items table with the products table in the sequel inventory database let's get 4266 01:34:21,910 --> 01:34:21,920 the sequel inventory database let's get 4267 01:34:21,920 --> 01:34:22,420 the sequel inventory database let's get started 4268 01:34:22,420 --> 01:34:22,430 started 4269 01:34:22,430 --> 01:34:26,680 started so select everything from the order 4270 01:34:26,680 --> 01:34:26,690 so select everything from the order 4271 01:34:26,690 --> 01:34:29,230 so select everything from the order items table let's give it an alias 4272 01:34:29,230 --> 01:34:29,240 items table let's give it an alias 4273 01:34:29,240 --> 01:34:32,080 items table let's give it an alias straight away we want to join this with 4274 01:34:32,080 --> 01:34:32,090 straight away we want to join this with 4275 01:34:32,090 --> 01:34:34,390 straight away we want to join this with the products table this products table 4276 01:34:34,390 --> 01:34:34,400 the products table this products table 4277 01:34:34,400 --> 01:34:36,760 the products table this products table is part of the sequel inventory database 4278 01:34:36,760 --> 01:34:36,770 is part of the sequel inventory database 4279 01:34:36,770 --> 01:34:39,280 is part of the sequel inventory database so we'll have to prefix this with the 4280 01:34:39,280 --> 01:34:39,290 so we'll have to prefix this with the 4281 01:34:39,290 --> 01:34:41,260 so we'll have to prefix this with the name of its database so we type out 4282 01:34:41,260 --> 01:34:41,270 name of its database so we type out 4283 01:34:41,270 --> 01:34:45,760 name of its database so we type out sequel inventory dot now once again we 4284 01:34:45,760 --> 01:34:45,770 sequel inventory dot now once again we 4285 01:34:45,770 --> 01:34:48,790 sequel inventory dot now once again we can give this an alias like P then type 4286 01:34:48,790 --> 01:34:48,800 can give this an alias like P then type 4287 01:34:48,800 --> 01:34:51,190 can give this an alias like P then type out our joint condition so oh I dot 4288 01:34:51,190 --> 01:34:51,200 out our joint condition so oh I dot 4289 01:34:51,200 --> 01:34:54,240 out our joint condition so oh I dot product ID should be the same as P dot 4290 01:34:54,240 --> 01:34:54,250 product ID should be the same as P dot 4291 01:34:54,250 --> 01:34:58,690 product ID should be the same as P dot product ID let's run the query there you 4292 01:34:58,690 --> 01:34:58,700 product ID let's run the query there you 4293 01:34:58,700 --> 01:35:01,600 product ID let's run the query there you go so we successfully join tables across 4294 01:35:01,600 --> 01:35:01,610 go so we successfully join tables across 4295 01:35:01,610 --> 01:35:04,480 go so we successfully join tables across multiple databases now note that we're 4296 01:35:04,480 --> 01:35:04,490 multiple databases now note that we're 4297 01:35:04,490 --> 01:35:06,550 multiple databases now note that we're prefixing the products table with the 4298 01:35:06,550 --> 01:35:06,560 prefixing the products table with the 4299 01:35:06,560 --> 01:35:08,770 prefixing the products table with the name of its database because the current 4300 01:35:08,770 --> 01:35:08,780 name of its database because the current 4301 01:35:08,780 --> 01:35:10,360 name of its database because the current database that we're writing this query 4302 01:35:10,360 --> 01:35:10,370 database that we're writing this query 4303 01:35:10,370 --> 01:35:12,420 database that we're writing this query against is the sequel store database 4304 01:35:12,420 --> 01:35:12,430 against is the sequel store database 4305 01:35:12,430 --> 01:35:15,790 against is the sequel store database take a look in the Navigator panel the 4306 01:35:15,790 --> 01:35:15,800 take a look in the Navigator panel the 4307 01:35:15,800 --> 01:35:17,560 take a look in the Navigator panel the sequel store database is displayed in 4308 01:35:17,560 --> 01:35:17,570 sequel store database is displayed in 4309 01:35:17,570 --> 01:35:22,210 sequel store database is displayed in port because earlier we wrote the use 4310 01:35:22,210 --> 01:35:22,220 port because earlier we wrote the use 4311 01:35:22,220 --> 01:35:25,270 port because earlier we wrote the use statement to select a database that was 4312 01:35:25,270 --> 01:35:25,280 statement to select a database that was 4313 01:35:25,280 --> 01:35:28,300 statement to select a database that was sequel store now what if we select the 4314 01:35:28,300 --> 01:35:28,310 sequel store now what if we select the 4315 01:35:28,310 --> 01:35:30,490 sequel store now what if we select the sequel inventory database let's see what 4316 01:35:30,490 --> 01:35:30,500 sequel inventory database let's see what 4317 01:35:30,500 --> 01:35:34,600 sequel inventory database let's see what happens so sequel inventory now because 4318 01:35:34,600 --> 01:35:34,610 happens so sequel inventory now because 4319 01:35:34,610 --> 01:35:35,410 happens so sequel inventory now because we have multiple 4320 01:35:35,410 --> 01:35:35,420 we have multiple 4321 01:35:35,420 --> 01:35:36,850 we have multiple statements we have to terminate this 4322 01:35:36,850 --> 01:35:36,860 statements we have to terminate this 4323 01:35:36,860 --> 01:35:39,400 statements we have to terminate this with a semicolon now we want to select 4324 01:35:39,400 --> 01:35:39,410 with a semicolon now we want to select 4325 01:35:39,410 --> 01:35:41,020 with a semicolon now we want to select everything from the order items table 4326 01:35:41,020 --> 01:35:41,030 everything from the order items table 4327 01:35:41,030 --> 01:35:43,630 everything from the order items table but we don't have this table inside of 4328 01:35:43,630 --> 01:35:43,640 but we don't have this table inside of 4329 01:35:43,640 --> 01:35:46,990 but we don't have this table inside of this database so now we'll have to 4330 01:35:46,990 --> 01:35:47,000 this database so now we'll have to 4331 01:35:47,000 --> 01:35:49,390 this database so now we'll have to prefix this table with a name of its 4332 01:35:49,390 --> 01:35:49,400 prefix this table with a name of its 4333 01:35:49,400 --> 01:35:53,130 prefix this table with a name of its database that is sequel underline store 4334 01:35:53,130 --> 01:35:53,140 database that is sequel underline store 4335 01:35:53,140 --> 01:35:56,590 database that is sequel underline store let's execute the query okay everything 4336 01:35:56,590 --> 01:35:56,600 let's execute the query okay everything 4337 01:35:56,600 --> 01:35:58,510 let's execute the query okay everything works beautifully so here's the lesson 4338 01:35:58,510 --> 01:35:58,520 works beautifully so here's the lesson 4339 01:35:58,520 --> 01:36:01,510 works beautifully so here's the lesson you only have to prefix the tables that 4340 01:36:01,510 --> 01:36:01,520 you only have to prefix the tables that 4341 01:36:01,520 --> 01:36:03,850 you only have to prefix the tables that are not part of the current database in 4342 01:36:03,850 --> 01:36:03,860 are not part of the current database in 4343 01:36:03,860 --> 01:36:05,740 are not part of the current database in other words your query will be different 4344 01:36:05,740 --> 01:36:05,750 other words your query will be different 4345 01:36:05,750 --> 01:36:13,380 other words your query will be different depending on the current database 4346 01:36:13,380 --> 01:36:13,390 4347 01:36:13,390 --> 01:36:16,180 in sequel we can also join a table with 4348 01:36:16,180 --> 01:36:16,190 in sequel we can also join a table with 4349 01:36:16,190 --> 01:36:18,820 in sequel we can also join a table with itself let me show you an example take a 4350 01:36:18,820 --> 01:36:18,830 itself let me show you an example take a 4351 01:36:18,830 --> 01:36:23,140 itself let me show you an example take a look at this database sequel HR in this 4352 01:36:23,140 --> 01:36:23,150 look at this database sequel HR in this 4353 01:36:23,150 --> 01:36:24,820 look at this database sequel HR in this database we have these two tables 4354 01:36:24,820 --> 01:36:24,830 database we have these two tables 4355 01:36:24,830 --> 01:36:27,580 database we have these two tables employees and offices let's take a look 4356 01:36:27,580 --> 01:36:27,590 employees and offices let's take a look 4357 01:36:27,590 --> 01:36:33,580 employees and offices let's take a look at the data in the employees table there 4358 01:36:33,580 --> 01:36:33,590 at the data in the employees table there 4359 01:36:33,590 --> 01:36:35,410 at the data in the employees table there you go so here we have these columns 4360 01:36:35,410 --> 01:36:35,420 you go so here we have these columns 4361 01:36:35,420 --> 01:36:38,740 you go so here we have these columns employee ID first name last name their 4362 01:36:38,740 --> 01:36:38,750 employee ID first name last name their 4363 01:36:38,750 --> 01:36:43,570 employee ID first name last name their job title salary and reports - this is 4364 01:36:43,570 --> 01:36:43,580 job title salary and reports - this is 4365 01:36:43,580 --> 01:36:45,939 job title salary and reports - this is the idea of the manager for this person 4366 01:36:45,939 --> 01:36:45,949 the idea of the manager for this person 4367 01:36:45,949 --> 01:36:48,459 the idea of the manager for this person or this employee now once again we don't 4368 01:36:48,459 --> 01:36:48,469 or this employee now once again we don't 4369 01:36:48,469 --> 01:36:50,080 or this employee now once again we don't want to repeat the manager's information 4370 01:36:50,080 --> 01:36:50,090 want to repeat the manager's information 4371 01:36:50,090 --> 01:36:51,790 want to repeat the manager's information here like their phone number their 4372 01:36:51,790 --> 01:36:51,800 here like their phone number their 4373 01:36:51,800 --> 01:36:53,830 here like their phone number their address because this information can 4374 01:36:53,830 --> 01:36:53,840 address because this information can 4375 01:36:53,840 --> 01:36:55,840 address because this information can change in the future so we are only 4376 01:36:55,840 --> 01:36:55,850 change in the future so we are only 4377 01:36:55,850 --> 01:36:58,450 change in the future so we are only using their identifier or their ID to 4378 01:36:58,450 --> 01:36:58,460 using their identifier or their ID to 4379 01:36:58,460 --> 01:37:01,090 using their identifier or their ID to refer to them in this table now where 4380 01:37:01,090 --> 01:37:01,100 refer to them in this table now where 4381 01:37:01,100 --> 01:37:02,530 refer to them in this table now where can we find the information about this 4382 01:37:02,530 --> 01:37:02,540 can we find the information about this 4383 01:37:02,540 --> 01:37:05,140 can we find the information about this manager well this manager is actually an 4384 01:37:05,140 --> 01:37:05,150 manager well this manager is actually an 4385 01:37:05,150 --> 01:37:07,620 manager well this manager is actually an employee of the same organization so 4386 01:37:07,620 --> 01:37:07,630 employee of the same organization so 4387 01:37:07,630 --> 01:37:10,450 employee of the same organization so look at this example the manager IDs 4388 01:37:10,450 --> 01:37:10,460 look at this example the manager IDs 4389 01:37:10,460 --> 01:37:13,930 look at this example the manager IDs three seven two seven zero now if you 4390 01:37:13,930 --> 01:37:13,940 three seven two seven zero now if you 4391 01:37:13,940 --> 01:37:16,120 three seven two seven zero now if you look on the left side here's the idea of 4392 01:37:16,120 --> 01:37:16,130 look on the left side here's the idea of 4393 01:37:16,130 --> 01:37:18,130 look on the left side here's the idea of that manager which is another employee 4394 01:37:18,130 --> 01:37:18,140 that manager which is another employee 4395 01:37:18,140 --> 01:37:20,560 that manager which is another employee now who's the manager for this employee 4396 01:37:20,560 --> 01:37:20,570 now who's the manager for this employee 4397 01:37:20,570 --> 01:37:23,140 now who's the manager for this employee let's take a look we don't have any 4398 01:37:23,140 --> 01:37:23,150 let's take a look we don't have any 4399 01:37:23,150 --> 01:37:25,479 let's take a look we don't have any values here so the value for this cell 4400 01:37:25,479 --> 01:37:25,489 values here so the value for this cell 4401 01:37:25,489 --> 01:37:27,850 values here so the value for this cell is no so this employee doesn't have a 4402 01:37:27,850 --> 01:37:27,860 is no so this employee doesn't have a 4403 01:37:27,860 --> 01:37:30,390 is no so this employee doesn't have a manager and that means they are the CEO 4404 01:37:30,390 --> 01:37:30,400 manager and that means they are the CEO 4405 01:37:30,400 --> 01:37:32,830 manager and that means they are the CEO so now let's go ahead and write a query 4406 01:37:32,830 --> 01:37:32,840 so now let's go ahead and write a query 4407 01:37:32,840 --> 01:37:35,650 so now let's go ahead and write a query to join this table with itself so we can 4408 01:37:35,650 --> 01:37:35,660 to join this table with itself so we can 4409 01:37:35,660 --> 01:37:37,150 to join this table with itself so we can select the name of each employee and 4410 01:37:37,150 --> 01:37:37,160 select the name of each employee and 4411 01:37:37,160 --> 01:37:39,850 select the name of each employee and their manager back to a query window 4412 01:37:39,850 --> 01:37:39,860 their manager back to a query window 4413 01:37:39,860 --> 01:37:43,240 their manager back to a query window first we need to select the sequel HR 4414 01:37:43,240 --> 01:37:43,250 first we need to select the sequel HR 4415 01:37:43,250 --> 01:37:47,729 first we need to select the sequel HR database next we select everything from 4416 01:37:47,729 --> 01:37:47,739 database next we select everything from 4417 01:37:47,739 --> 01:37:51,520 database next we select everything from the employees table we give them alias 4418 01:37:51,520 --> 01:37:51,530 the employees table we give them alias 4419 01:37:51,530 --> 01:37:54,310 the employees table we give them alias like e now when it's join this table 4420 01:37:54,310 --> 01:37:54,320 like e now when it's join this table 4421 01:37:54,320 --> 01:37:56,740 like e now when it's join this table with itself so once again we type out 4422 01:37:56,740 --> 01:37:56,750 with itself so once again we type out 4423 01:37:56,750 --> 01:37:59,010 with itself so once again we type out employees but we need a different alias 4424 01:37:59,010 --> 01:37:59,020 employees but we need a different alias 4425 01:37:59,020 --> 01:38:02,229 employees but we need a different alias what should we call this alias well we 4426 01:38:02,229 --> 01:38:02,239 what should we call this alias well we 4427 01:38:02,239 --> 01:38:04,090 what should we call this alias well we want to join this table with itself so 4428 01:38:04,090 --> 01:38:04,100 want to join this table with itself so 4429 01:38:04,100 --> 01:38:07,150 want to join this table with itself so we can find the managers right so we can 4430 01:38:07,150 --> 01:38:07,160 we can find the managers right so we can 4431 01:38:07,160 --> 01:38:10,810 we can find the managers right so we can use M as in short for managers now this 4432 01:38:10,810 --> 01:38:10,820 use M as in short for managers now this 4433 01:38:10,820 --> 01:38:13,750 use M as in short for managers now this type at our joint condition so from the 4434 01:38:13,750 --> 01:38:13,760 type at our joint condition so from the 4435 01:38:13,760 --> 01:38:16,540 type at our joint condition so from the employees table we need to join the 4436 01:38:16,540 --> 01:38:16,550 employees table we need to join the 4437 01:38:16,550 --> 01:38:19,689 employees table we need to join the reports under line to column to the 4438 01:38:19,689 --> 01:38:19,699 reports under line to column to the 4439 01:38:19,699 --> 01:38:21,729 reports under line to column to the managers table which is basically the 4440 01:38:21,729 --> 01:38:21,739 managers table which is basically the 4441 01:38:21,739 --> 01:38:23,080 managers table which is basically the employees table itself 4442 01:38:23,080 --> 01:38:23,090 employees table itself 4443 01:38:23,090 --> 01:38:25,920 employees table itself and what column that is employee 4444 01:38:25,920 --> 01:38:25,930 and what column that is employee 4445 01:38:25,930 --> 01:38:29,260 and what column that is employee underlined ID now let's execute this 4446 01:38:29,260 --> 01:38:29,270 underlined ID now let's execute this 4447 01:38:29,270 --> 01:38:34,420 underlined ID now let's execute this query and see what we get so we see all 4448 01:38:34,420 --> 01:38:34,430 query and see what we get so we see all 4449 01:38:34,430 --> 01:38:36,120 query and see what we get so we see all the columns from the employees table 4450 01:38:36,120 --> 01:38:36,130 the columns from the employees table 4451 01:38:36,130 --> 01:38:38,470 the columns from the employees table repeated the first set of columns 4452 01:38:38,470 --> 01:38:38,480 repeated the first set of columns 4453 01:38:38,480 --> 01:38:39,970 repeated the first set of columns represent information about the 4454 01:38:39,970 --> 01:38:39,980 represent information about the 4455 01:38:39,980 --> 01:38:42,280 represent information about the employees and then after that we have 4456 01:38:42,280 --> 01:38:42,290 employees and then after that we have 4457 01:38:42,290 --> 01:38:45,130 employees and then after that we have information about the manager in this 4458 01:38:45,130 --> 01:38:45,140 information about the manager in this 4459 01:38:45,140 --> 01:38:47,230 information about the manager in this case we have only one manager in this 4460 01:38:47,230 --> 01:38:47,240 case we have only one manager in this 4461 01:38:47,240 --> 01:38:49,570 case we have only one manager in this table but with this technique we can 4462 01:38:49,570 --> 01:38:49,580 table but with this technique we can 4463 01:38:49,580 --> 01:38:51,820 table but with this technique we can easily create an organization chart we 4464 01:38:51,820 --> 01:38:51,830 easily create an organization chart we 4465 01:38:51,830 --> 01:38:54,130 easily create an organization chart we can have a hierarchy of managers now 4466 01:38:54,130 --> 01:38:54,140 can have a hierarchy of managers now 4467 01:38:54,140 --> 01:38:56,230 can have a hierarchy of managers now let's simplify our query and select only 4468 01:38:56,230 --> 01:38:56,240 let's simplify our query and select only 4469 01:38:56,240 --> 01:38:58,210 let's simplify our query and select only the name of the employee and their 4470 01:38:58,210 --> 01:38:58,220 the name of the employee and their 4471 01:38:58,220 --> 01:39:03,220 the name of the employee and their manager so back here since every column 4472 01:39:03,220 --> 01:39:03,230 manager so back here since every column 4473 01:39:03,230 --> 01:39:05,350 manager so back here since every column in the employees table is repeated twice 4474 01:39:05,350 --> 01:39:05,360 in the employees table is repeated twice 4475 01:39:05,360 --> 01:39:07,540 in the employees table is repeated twice we need to prefix each column with a 4476 01:39:07,540 --> 01:39:07,550 we need to prefix each column with a 4477 01:39:07,550 --> 01:39:10,480 we need to prefix each column with a table name for example from the 4478 01:39:10,480 --> 01:39:10,490 table name for example from the 4479 01:39:10,490 --> 01:39:12,930 table name for example from the employees table you want to get employee 4480 01:39:12,930 --> 01:39:12,940 employees table you want to get employee 4481 01:39:12,940 --> 01:39:18,250 employees table you want to get employee ID as well as the first name and then 4482 01:39:18,250 --> 01:39:18,260 ID as well as the first name and then 4483 01:39:18,260 --> 01:39:20,110 ID as well as the first name and then from the managers table you want to 4484 01:39:20,110 --> 01:39:20,120 from the managers table you want to 4485 01:39:20,120 --> 01:39:23,410 from the managers table you want to select the first name as well so every 4486 01:39:23,410 --> 01:39:23,420 select the first name as well so every 4487 01:39:23,420 --> 01:39:25,960 select the first name as well so every column should be prefixed with the table 4488 01:39:25,960 --> 01:39:25,970 column should be prefixed with the table 4489 01:39:25,970 --> 01:39:27,850 column should be prefixed with the table name or more accurately the alias 4490 01:39:27,850 --> 01:39:27,860 name or more accurately the alias 4491 01:39:27,860 --> 01:39:30,340 name or more accurately the alias because all these columns exist in two 4492 01:39:30,340 --> 01:39:30,350 because all these columns exist in two 4493 01:39:30,350 --> 01:39:33,160 because all these columns exist in two tables right let's go ahead and execute 4494 01:39:33,160 --> 01:39:33,170 tables right let's go ahead and execute 4495 01:39:33,170 --> 01:39:37,000 tables right let's go ahead and execute this query so this is what we get 4496 01:39:37,000 --> 01:39:37,010 this query so this is what we get 4497 01:39:37,010 --> 01:39:39,880 this query so this is what we get employee ID first name and here's the 4498 01:39:39,880 --> 01:39:39,890 employee ID first name and here's the 4499 01:39:39,890 --> 01:39:42,130 employee ID first name and here's the managers first name we can improve this 4500 01:39:42,130 --> 01:39:42,140 managers first name we can improve this 4501 01:39:42,140 --> 01:39:44,110 managers first name we can improve this query by giving an alias to this column 4502 01:39:44,110 --> 01:39:44,120 query by giving an alias to this column 4503 01:39:44,120 --> 01:39:46,150 query by giving an alias to this column because it doesn't make sense to have to 4504 01:39:46,150 --> 01:39:46,160 because it doesn't make sense to have to 4505 01:39:46,160 --> 01:39:50,290 because it doesn't make sense to have to first name columns so let's give an 4506 01:39:50,290 --> 01:39:50,300 first name columns so let's give an 4507 01:39:50,300 --> 01:39:54,130 first name columns so let's give an alias to the third column manager now 4508 01:39:54,130 --> 01:39:54,140 alias to the third column manager now 4509 01:39:54,140 --> 01:39:57,609 alias to the third column manager now let's execute it one more time 4510 01:39:57,609 --> 01:39:57,619 4511 01:39:57,619 --> 01:40:00,250 and here's the end result so we have the 4512 01:40:00,250 --> 01:40:00,260 and here's the end result so we have the 4513 01:40:00,260 --> 01:40:04,149 and here's the end result so we have the employee ID first name and manager so 4514 01:40:04,149 --> 01:40:04,159 employee ID first name and manager so 4515 01:40:04,159 --> 01:40:06,339 employee ID first name and manager so joining a table with itself is pretty 4516 01:40:06,339 --> 01:40:06,349 joining a table with itself is pretty 4517 01:40:06,349 --> 01:40:08,020 joining a table with itself is pretty much the same as joining a table with 4518 01:40:08,020 --> 01:40:08,030 much the same as joining a table with 4519 01:40:08,030 --> 01:40:10,510 much the same as joining a table with another table the only difference is 4520 01:40:10,510 --> 01:40:10,520 another table the only difference is 4521 01:40:10,520 --> 01:40:12,700 another table the only difference is that we have to use different aliases 4522 01:40:12,700 --> 01:40:12,710 that we have to use different aliases 4523 01:40:12,710 --> 01:40:15,520 that we have to use different aliases and we have to prefix each column with 4524 01:40:15,520 --> 01:40:15,530 and we have to prefix each column with 4525 01:40:15,530 --> 01:40:18,070 and we have to prefix each column with an alias this is what we call a self 4526 01:40:18,070 --> 01:40:18,080 an alias this is what we call a self 4527 01:40:18,080 --> 01:40:20,740 an alias this is what we call a self join next I'm gonna show you how to join 4528 01:40:20,740 --> 01:40:20,750 join next I'm gonna show you how to join 4529 01:40:20,750 --> 01:40:28,629 join next I'm gonna show you how to join more than two tables in this tutorial 4530 01:40:28,629 --> 01:40:28,639 more than two tables in this tutorial 4531 01:40:28,639 --> 01:40:30,399 more than two tables in this tutorial I'm gonna show you how to join more than 4532 01:40:30,399 --> 01:40:30,409 I'm gonna show you how to join more than 4533 01:40:30,409 --> 01:40:33,070 I'm gonna show you how to join more than two tables when writing a query for 4534 01:40:33,070 --> 01:40:33,080 two tables when writing a query for 4535 01:40:33,080 --> 01:40:34,750 two tables when writing a query for example back to our sequel store 4536 01:40:34,750 --> 01:40:34,760 example back to our sequel store 4537 01:40:34,760 --> 01:40:37,930 example back to our sequel store database look at the orders table now 4538 01:40:37,930 --> 01:40:37,940 database look at the orders table now 4539 01:40:37,940 --> 01:40:39,939 database look at the orders table now you know how to write a query to join 4540 01:40:39,939 --> 01:40:39,949 you know how to write a query to join 4541 01:40:39,949 --> 01:40:42,070 you know how to write a query to join this table with the customers table to 4542 01:40:42,070 --> 01:40:42,080 this table with the customers table to 4543 01:40:42,080 --> 01:40:43,540 this table with the customers table to return information about the customer 4544 01:40:43,540 --> 01:40:43,550 return information about the customer 4545 01:40:43,550 --> 01:40:46,120 return information about the customer who placed each order but here we also 4546 01:40:46,120 --> 01:40:46,130 who placed each order but here we also 4547 01:40:46,130 --> 01:40:48,939 who placed each order but here we also have another column status which is 4548 01:40:48,939 --> 01:40:48,949 have another column status which is 4549 01:40:48,949 --> 01:40:51,790 have another column status which is similar to the customer ID column so the 4550 01:40:51,790 --> 01:40:51,800 similar to the customer ID column so the 4551 01:40:51,800 --> 01:40:53,560 similar to the customer ID column so the name of these statuses are not stored in 4552 01:40:53,560 --> 01:40:53,570 name of these statuses are not stored in 4553 01:40:53,570 --> 01:40:55,600 name of these statuses are not stored in this table there are somewhere else in 4554 01:40:55,600 --> 01:40:55,610 this table there are somewhere else in 4555 01:40:55,610 --> 01:40:57,970 this table there are somewhere else in the order statuses table let's have a 4556 01:40:57,970 --> 01:40:57,980 the order statuses table let's have a 4557 01:40:57,980 --> 01:41:00,669 the order statuses table let's have a quick look here so our orders can be 4558 01:41:00,669 --> 01:41:00,679 quick look here so our orders can be 4559 01:41:00,679 --> 01:41:03,580 quick look here so our orders can be their process shipped or delivered and 4560 01:41:03,580 --> 01:41:03,590 their process shipped or delivered and 4561 01:41:03,590 --> 01:41:06,129 their process shipped or delivered and these are the identifiers for each of 4562 01:41:06,129 --> 01:41:06,139 these are the identifiers for each of 4563 01:41:06,139 --> 01:41:08,320 these are the identifiers for each of these statuses now back to our orders 4564 01:41:08,320 --> 01:41:08,330 these statuses now back to our orders 4565 01:41:08,330 --> 01:41:11,439 these statuses now back to our orders table in a status column we store the 4566 01:41:11,439 --> 01:41:11,449 table in a status column we store the 4567 01:41:11,449 --> 01:41:14,649 table in a status column we store the order status ID so now we should write 4568 01:41:14,649 --> 01:41:14,659 order status ID so now we should write 4569 01:41:14,659 --> 01:41:16,930 order status ID so now we should write the query to join the orders table with 4570 01:41:16,930 --> 01:41:16,940 the query to join the orders table with 4571 01:41:16,940 --> 01:41:20,080 the query to join the orders table with two tables the customers table add order 4572 01:41:20,080 --> 01:41:20,090 two tables the customers table add order 4573 01:41:20,090 --> 01:41:22,359 two tables the customers table add order statuses table the result of this query 4574 01:41:22,359 --> 01:41:22,369 statuses table the result of this query 4575 01:41:22,369 --> 01:41:25,479 statuses table the result of this query is going to look like this so for each 4576 01:41:25,479 --> 01:41:25,489 is going to look like this so for each 4577 01:41:25,489 --> 01:41:28,629 is going to look like this so for each order we see the order ID the date the 4578 01:41:28,629 --> 01:41:28,639 order we see the order ID the date the 4579 01:41:28,639 --> 01:41:30,399 order we see the order ID the date the first and last name of the customer and 4580 01:41:30,399 --> 01:41:30,409 first and last name of the customer and 4581 01:41:30,409 --> 01:41:32,830 first and last name of the customer and finally the status of the order this is 4582 01:41:32,830 --> 01:41:32,840 finally the status of the order this is 4583 01:41:32,840 --> 01:41:34,540 finally the status of the order this is a beautiful report we can create for our 4584 01:41:34,540 --> 01:41:34,550 a beautiful report we can create for our 4585 01:41:34,550 --> 01:41:36,729 a beautiful report we can create for our users so let me show you how to write 4586 01:41:36,729 --> 01:41:36,739 users so let me show you how to write 4587 01:41:36,739 --> 01:41:37,300 users so let me show you how to write this query 4588 01:41:37,300 --> 01:41:37,310 this query 4589 01:41:37,310 --> 01:41:40,030 this query back to our query editor first we need 4590 01:41:40,030 --> 01:41:40,040 back to our query editor first we need 4591 01:41:40,040 --> 01:41:43,720 back to our query editor first we need to select the sequel store database now 4592 01:41:43,720 --> 01:41:43,730 to select the sequel store database now 4593 01:41:43,730 --> 01:41:46,419 to select the sequel store database now we need to select everything from the 4594 01:41:46,419 --> 01:41:46,429 we need to select everything from the 4595 01:41:46,429 --> 01:41:49,600 we need to select everything from the orders table let's give it an alias next 4596 01:41:49,600 --> 01:41:49,610 orders table let's give it an alias next 4597 01:41:49,610 --> 01:41:51,280 orders table let's give it an alias next we need to join this with a customers 4598 01:41:51,280 --> 01:41:51,290 we need to join this with a customers 4599 01:41:51,290 --> 01:41:56,290 we need to join this with a customers table on oh that customer ID should be a 4600 01:41:56,290 --> 01:41:56,300 table on oh that customer ID should be a 4601 01:41:56,300 --> 01:42:00,189 table on oh that customer ID should be a cool to see that customer ID nothing new 4602 01:42:00,189 --> 01:42:00,199 cool to see that customer ID nothing new 4603 01:42:00,199 --> 01:42:03,310 cool to see that customer ID nothing new so far exactly like before now here we 4604 01:42:03,310 --> 01:42:03,320 so far exactly like before now here we 4605 01:42:03,320 --> 01:42:06,790 so far exactly like before now here we can write another join keyword to join 4606 01:42:06,790 --> 01:42:06,800 can write another join keyword to join 4607 01:42:06,800 --> 01:42:08,950 can write another join keyword to join the orders table with order statuses 4608 01:42:08,950 --> 01:42:08,960 the orders table with order statuses 4609 01:42:08,960 --> 01:42:11,469 the orders table with order statuses table so we type out order 4610 01:42:11,469 --> 01:42:11,479 table so we type out order 4611 01:42:11,479 --> 01:42:14,830 table so we type out order statuses and also give it an alias like 4612 01:42:14,830 --> 01:42:14,840 statuses and also give it an alias like 4613 01:42:14,840 --> 01:42:19,299 statuses and also give it an alias like OS what is our joint condition well I 4614 01:42:19,299 --> 01:42:19,309 OS what is our joint condition well I 4615 01:42:19,309 --> 01:42:22,419 OS what is our joint condition well I can order stable here we have is status 4616 01:42:22,419 --> 01:42:22,429 can order stable here we have is status 4617 01:42:22,429 --> 01:42:24,640 can order stable here we have is status column so the value in this column 4618 01:42:24,640 --> 01:42:24,650 column so the value in this column 4619 01:42:24,650 --> 01:42:28,540 column so the value in this column should be equal to the order status ID 4620 01:42:28,540 --> 01:42:28,550 should be equal to the order status ID 4621 01:42:28,550 --> 01:42:32,199 should be equal to the order status ID column in order statuses table right so 4622 01:42:32,199 --> 01:42:32,209 column in order statuses table right so 4623 01:42:32,209 --> 01:42:35,020 column in order statuses table right so back to the query so orders table dot 4624 01:42:35,020 --> 01:42:35,030 back to the query so orders table dot 4625 01:42:35,030 --> 01:42:38,109 back to the query so orders table dot status should be equal to order status 4626 01:42:38,109 --> 01:42:38,119 status should be equal to order status 4627 01:42:38,119 --> 01:42:42,160 status should be equal to order status dot order status ID make sure to get the 4628 01:42:42,160 --> 01:42:42,170 dot order status ID make sure to get the 4629 01:42:42,170 --> 01:42:43,989 dot order status ID make sure to get the name right don't have a typo otherwise 4630 01:42:43,989 --> 01:42:43,999 name right don't have a typo otherwise 4631 01:42:43,999 --> 01:42:46,089 name right don't have a typo otherwise you're gonna get an error so this is how 4632 01:42:46,089 --> 01:42:46,099 you're gonna get an error so this is how 4633 01:42:46,099 --> 01:42:48,699 you're gonna get an error so this is how we can join three tables now in the real 4634 01:42:48,699 --> 01:42:48,709 we can join three tables now in the real 4635 01:42:48,709 --> 01:42:50,500 we can join three tables now in the real world as you work on more complex 4636 01:42:50,500 --> 01:42:50,510 world as you work on more complex 4637 01:42:50,510 --> 01:42:52,540 world as you work on more complex problems you might end up joining even 4638 01:42:52,540 --> 01:42:52,550 problems you might end up joining even 4639 01:42:52,550 --> 01:42:54,939 problems you might end up joining even ten tables so this is not uncommon in 4640 01:42:54,939 --> 01:42:54,949 ten tables so this is not uncommon in 4641 01:42:54,949 --> 01:42:57,370 ten tables so this is not uncommon in the sequel world now let's go ahead and 4642 01:42:57,370 --> 01:42:57,380 the sequel world now let's go ahead and 4643 01:42:57,380 --> 01:42:59,620 the sequel world now let's go ahead and execute this claim first we get the 4644 01:42:59,620 --> 01:42:59,630 execute this claim first we get the 4645 01:42:59,630 --> 01:43:01,569 execute this claim first we get the columns from the orders table followed 4646 01:43:01,569 --> 01:43:01,579 columns from the orders table followed 4647 01:43:01,579 --> 01:43:04,089 columns from the orders table followed by the columns from the customers table 4648 01:43:04,089 --> 01:43:04,099 by the columns from the customers table 4649 01:43:04,099 --> 01:43:06,819 by the columns from the customers table and so on this result is so complex and 4650 01:43:06,819 --> 01:43:06,829 and so on this result is so complex and 4651 01:43:06,829 --> 01:43:09,270 and so on this result is so complex and hard to extract information from so 4652 01:43:09,270 --> 01:43:09,280 hard to extract information from so 4653 01:43:09,280 --> 01:43:12,699 hard to extract information from so let's explicitly select a few columns 4654 01:43:12,699 --> 01:43:12,709 let's explicitly select a few columns 4655 01:43:12,709 --> 01:43:15,370 let's explicitly select a few columns here from the orders table we want to 4656 01:43:15,370 --> 01:43:15,380 here from the orders table we want to 4657 01:43:15,380 --> 01:43:19,029 here from the orders table we want to select the order ID column as well as 4658 01:43:19,029 --> 01:43:19,039 select the order ID column as well as 4659 01:43:19,039 --> 01:43:23,410 select the order ID column as well as the order date then from the customers 4660 01:43:23,410 --> 01:43:23,420 the order date then from the customers 4661 01:43:23,420 --> 01:43:25,540 the order date then from the customers table we want to select the first name 4662 01:43:25,540 --> 01:43:25,550 table we want to select the first name 4663 01:43:25,550 --> 01:43:29,830 table we want to select the first name and the last name and finally from the 4664 01:43:29,830 --> 01:43:29,840 and the last name and finally from the 4665 01:43:29,840 --> 01:43:31,660 and the last name and finally from the order statuses table we want to select 4666 01:43:31,660 --> 01:43:31,670 order statuses table we want to select 4667 01:43:31,670 --> 01:43:34,509 order statuses table we want to select the name column now we can give this an 4668 01:43:34,509 --> 01:43:34,519 the name column now we can give this an 4669 01:43:34,519 --> 01:43:37,930 the name column now we can give this an alias like status that's better let's 4670 01:43:37,930 --> 01:43:37,940 alias like status that's better let's 4671 01:43:37,940 --> 01:43:41,279 alias like status that's better let's execute the query one more time so 4672 01:43:41,279 --> 01:43:41,289 execute the query one more time so 4673 01:43:41,289 --> 01:43:44,020 execute the query one more time so here's the end result we have order ID 4674 01:43:44,020 --> 01:43:44,030 here's the end result we have order ID 4675 01:43:44,030 --> 01:43:46,140 here's the end result we have order ID or the date the name of the customer 4676 01:43:46,140 --> 01:43:46,150 or the date the name of the customer 4677 01:43:46,150 --> 01:43:52,560 or the date the name of the customer followed by the status of the order 4678 01:43:52,560 --> 01:43:52,570 4679 01:43:52,570 --> 01:43:55,120 all right for your exercise take a look 4680 01:43:55,120 --> 01:43:55,130 all right for your exercise take a look 4681 01:43:55,130 --> 01:43:58,000 all right for your exercise take a look at this equal invoicing database here we 4682 01:43:58,000 --> 01:43:58,010 at this equal invoicing database here we 4683 01:43:58,010 --> 01:44:00,189 at this equal invoicing database here we have this table payments and these are 4684 01:44:00,189 --> 01:44:00,199 have this table payments and these are 4685 01:44:00,199 --> 01:44:02,380 have this table payments and these are the payments that each client has made 4686 01:44:02,380 --> 01:44:02,390 the payments that each client has made 4687 01:44:02,390 --> 01:44:04,990 the payments that each client has made towards a given invoice let's take a 4688 01:44:04,990 --> 01:44:05,000 towards a given invoice let's take a 4689 01:44:05,000 --> 01:44:07,600 towards a given invoice let's take a look at the data so we have these 4690 01:44:07,600 --> 01:44:07,610 look at the data so we have these 4691 01:44:07,610 --> 01:44:10,180 look at the data so we have these columns like client ID that identifies 4692 01:44:10,180 --> 01:44:10,190 columns like client ID that identifies 4693 01:44:10,190 --> 01:44:12,280 columns like client ID that identifies the client so we can join this table 4694 01:44:12,280 --> 01:44:12,290 the client so we can join this table 4695 01:44:12,290 --> 01:44:14,200 the client so we can join this table with the clients table to see the name 4696 01:44:14,200 --> 01:44:14,210 with the clients table to see the name 4697 01:44:14,210 --> 01:44:17,320 with the clients table to see the name of the clients next we have invoice ID 4698 01:44:17,320 --> 01:44:17,330 of the clients next we have invoice ID 4699 01:44:17,330 --> 01:44:20,439 of the clients next we have invoice ID you also have date amount and payment 4700 01:44:20,439 --> 01:44:20,449 you also have date amount and payment 4701 01:44:20,449 --> 01:44:22,600 you also have date amount and payment method so similarly we can join this 4702 01:44:22,600 --> 01:44:22,610 method so similarly we can join this 4703 01:44:22,610 --> 01:44:24,550 method so similarly we can join this table with the payment methods table 4704 01:44:24,550 --> 01:44:24,560 table with the payment methods table 4705 01:44:24,560 --> 01:44:27,160 table with the payment methods table here let's have a look at a data in this 4706 01:44:27,160 --> 01:44:27,170 here let's have a look at a data in this 4707 01:44:27,170 --> 01:44:28,900 here let's have a look at a data in this table these are the payment methods 4708 01:44:28,900 --> 01:44:28,910 table these are the payment methods 4709 01:44:28,910 --> 01:44:31,000 table these are the payment methods credit card cash paypal and wire 4710 01:44:31,000 --> 01:44:31,010 credit card cash paypal and wire 4711 01:44:31,010 --> 01:44:33,490 credit card cash paypal and wire transfer so back to the payments table I 4712 01:44:33,490 --> 01:44:33,500 transfer so back to the payments table I 4713 01:44:33,500 --> 01:44:35,650 transfer so back to the payments table I want you to write the query and join 4714 01:44:35,650 --> 01:44:35,660 want you to write the query and join 4715 01:44:35,660 --> 01:44:37,780 want you to write the query and join this table with the payment methods 4716 01:44:37,780 --> 01:44:37,790 this table with the payment methods 4717 01:44:37,790 --> 01:44:39,520 this table with the payment methods table as well as the clients table 4718 01:44:39,520 --> 01:44:39,530 table as well as the clients table 4719 01:44:39,530 --> 01:44:41,830 table as well as the clients table produce a report that shows the payment 4720 01:44:41,830 --> 01:44:41,840 produce a report that shows the payment 4721 01:44:41,840 --> 01:44:43,840 produce a report that shows the payment with more details such as the name of 4722 01:44:43,840 --> 01:44:43,850 with more details such as the name of 4723 01:44:43,850 --> 01:44:50,409 with more details such as the name of the client and the payment method 4724 01:44:50,409 --> 01:44:50,419 4725 01:44:50,419 --> 01:44:52,969 all right first we need to use the 4726 01:44:52,969 --> 01:44:52,979 all right first we need to use the 4727 01:44:52,979 --> 01:44:56,359 all right first we need to use the sequel invoicing database now we can 4728 01:44:56,359 --> 01:44:56,369 sequel invoicing database now we can 4729 01:44:56,369 --> 01:44:58,579 sequel invoicing database now we can select everything from the payments 4730 01:44:58,579 --> 01:44:58,589 select everything from the payments 4731 01:44:58,589 --> 01:45:01,699 select everything from the payments table which we call P next we need to 4732 01:45:01,699 --> 01:45:01,709 table which we call P next we need to 4733 01:45:01,709 --> 01:45:03,919 table which we call P next we need to join this with the clients table which 4734 01:45:03,919 --> 01:45:03,929 join this with the clients table which 4735 01:45:03,929 --> 01:45:08,989 join this with the clients table which we call it C on P client ID should be 4736 01:45:08,989 --> 01:45:08,999 we call it C on P client ID should be 4737 01:45:08,999 --> 01:45:12,379 we call it C on P client ID should be equal to C that client ID let me double 4738 01:45:12,379 --> 01:45:12,389 equal to C that client ID let me double 4739 01:45:12,389 --> 01:45:13,909 equal to C that client ID let me double check the column name to make sure I got 4740 01:45:13,909 --> 01:45:13,919 check the column name to make sure I got 4741 01:45:13,919 --> 01:45:16,399 check the column name to make sure I got it right so back to the payments table 4742 01:45:16,399 --> 01:45:16,409 it right so back to the payments table 4743 01:45:16,409 --> 01:45:17,539 it right so back to the payments table the column is called 4744 01:45:17,539 --> 01:45:17,549 the column is called 4745 01:45:17,549 --> 01:45:20,029 the column is called client ID you also have a column called 4746 01:45:20,029 --> 01:45:20,039 client ID you also have a column called 4747 01:45:20,039 --> 01:45:23,839 client ID you also have a column called payment method that we should join to 4748 01:45:23,839 --> 01:45:23,849 payment method that we should join to 4749 01:45:23,849 --> 01:45:26,179 payment method that we should join to the payment method ID column of the 4750 01:45:26,179 --> 01:45:26,189 the payment method ID column of the 4751 01:45:26,189 --> 01:45:29,149 the payment method ID column of the payment methods table so back to the 4752 01:45:29,149 --> 01:45:29,159 payment methods table so back to the 4753 01:45:29,159 --> 01:45:32,059 payment methods table so back to the query once again we use a joint 4754 01:45:32,059 --> 01:45:32,069 query once again we use a joint 4755 01:45:32,069 --> 01:45:35,119 query once again we use a joint statement here join with payment methods 4756 01:45:35,119 --> 01:45:35,129 statement here join with payment methods 4757 01:45:35,129 --> 01:45:40,509 statement here join with payment methods we give it an alias pm on P dot payment 4758 01:45:40,509 --> 01:45:40,519 we give it an alias pm on P dot payment 4759 01:45:40,519 --> 01:45:42,979 we give it an alias pm on P dot payment underlying method should be equal to 4760 01:45:42,979 --> 01:45:42,989 underlying method should be equal to 4761 01:45:42,989 --> 01:45:47,149 underlying method should be equal to p.m. dot payment method ID make sure to 4762 01:45:47,149 --> 01:45:47,159 p.m. dot payment method ID make sure to 4763 01:45:47,159 --> 01:45:48,619 p.m. dot payment method ID make sure to type it out correctly otherwise you're 4764 01:45:48,619 --> 01:45:48,629 type it out correctly otherwise you're 4765 01:45:48,629 --> 01:45:51,229 type it out correctly otherwise you're gonna get an error so let's go ahead and 4766 01:45:51,229 --> 01:45:51,239 gonna get an error so let's go ahead and 4767 01:45:51,239 --> 01:45:53,869 gonna get an error so let's go ahead and execute the query after this point there 4768 01:45:53,869 --> 01:45:53,879 execute the query after this point there 4769 01:45:53,879 --> 01:45:56,449 execute the query after this point there you go finally let's hand pick the 4770 01:45:56,449 --> 01:45:56,459 you go finally let's hand pick the 4771 01:45:56,459 --> 01:46:02,000 you go finally let's hand pick the columns that make the most sense so from 4772 01:46:02,000 --> 01:46:02,010 columns that make the most sense so from 4773 01:46:02,010 --> 01:46:04,869 columns that make the most sense so from the payments table let's select a date 4774 01:46:04,869 --> 01:46:04,879 the payments table let's select a date 4775 01:46:04,879 --> 01:46:08,139 the payments table let's select a date followed by invoice ID 4776 01:46:08,139 --> 01:46:08,149 followed by invoice ID 4777 01:46:08,149 --> 01:46:11,149 followed by invoice ID what else do we have here so we have 4778 01:46:11,149 --> 01:46:11,159 what else do we have here so we have 4779 01:46:11,159 --> 01:46:14,419 what else do we have here so we have client ID invoice ID date amount and 4780 01:46:14,419 --> 01:46:14,429 client ID invoice ID date amount and 4781 01:46:14,429 --> 01:46:16,429 client ID invoice ID date amount and payment method I'm gonna pick the amount 4782 01:46:16,429 --> 01:46:16,439 payment method I'm gonna pick the amount 4783 01:46:16,439 --> 01:46:18,799 payment method I'm gonna pick the amount column from here as well so back to the 4784 01:46:18,799 --> 01:46:18,809 column from here as well so back to the 4785 01:46:18,809 --> 01:46:22,879 column from here as well so back to the query P dot amount now we need to add 4786 01:46:22,879 --> 01:46:22,889 query P dot amount now we need to add 4787 01:46:22,889 --> 01:46:24,979 query P dot amount now we need to add information about the client let's take 4788 01:46:24,979 --> 01:46:24,989 information about the client let's take 4789 01:46:24,989 --> 01:46:29,599 information about the client let's take a look at this table clients so here we 4790 01:46:29,599 --> 01:46:29,609 a look at this table clients so here we 4791 01:46:29,609 --> 01:46:32,509 a look at this table clients so here we have columns like name address city and 4792 01:46:32,509 --> 01:46:32,519 have columns like name address city and 4793 01:46:32,519 --> 01:46:34,129 have columns like name address city and so on all we need here is the name 4794 01:46:34,129 --> 01:46:34,139 so on all we need here is the name 4795 01:46:34,139 --> 01:46:37,099 so on all we need here is the name column so back to the query from the 4796 01:46:37,099 --> 01:46:37,109 column so back to the query from the 4797 01:46:37,109 --> 01:46:39,079 column so back to the query from the clients table let's select the name 4798 01:46:39,079 --> 01:46:39,089 clients table let's select the name 4799 01:46:39,089 --> 01:46:41,359 clients table let's select the name column and finally from the payment 4800 01:46:41,359 --> 01:46:41,369 column and finally from the payment 4801 01:46:41,369 --> 01:46:43,699 column and finally from the payment method table let's select what is that 4802 01:46:43,699 --> 01:46:43,709 method table let's select what is that 4803 01:46:43,709 --> 01:46:44,500 method table let's select what is that column called 4804 01:46:44,500 --> 01:46:44,510 column called 4805 01:46:44,510 --> 01:46:49,849 column called it's called name so back to the query PM 4806 01:46:49,849 --> 01:46:49,859 it's called name so back to the query PM 4807 01:46:49,859 --> 01:46:53,000 it's called name so back to the query PM dot name so here's the end result now we 4808 01:46:53,000 --> 01:46:53,010 dot name so here's the end result now we 4809 01:46:53,010 --> 01:46:54,589 dot name so here's the end result now we can put these columns in any order that 4810 01:46:54,589 --> 01:46:54,599 can put these columns in any order that 4811 01:46:54,599 --> 01:46:56,479 can put these columns in any order that we want it doesn't really matter let's 4812 01:46:56,479 --> 01:46:56,489 we want it doesn't really matter let's 4813 01:46:56,489 --> 01:46:57,770 we want it doesn't really matter let's execute the query and make sure 4814 01:46:57,770 --> 01:46:57,780 execute the query and make sure 4815 01:46:57,780 --> 01:47:02,400 execute the query and make sure everything works so honest 4816 01:47:02,400 --> 01:47:02,410 everything works so honest 4817 01:47:02,410 --> 01:47:04,740 everything works so honest eight for this invoice we have in 4818 01:47:04,740 --> 01:47:04,750 eight for this invoice we have in 4819 01:47:04,750 --> 01:47:07,080 eight for this invoice we have in payment for this amount by this client 4820 01:47:07,080 --> 01:47:07,090 payment for this amount by this client 4821 01:47:07,090 --> 01:47:13,640 payment for this amount by this client using a credit card 4822 01:47:13,640 --> 01:47:13,650 4823 01:47:13,650 --> 01:47:15,960 in all the examples you have seen so far 4824 01:47:15,960 --> 01:47:15,970 in all the examples you have seen so far 4825 01:47:15,970 --> 01:47:18,840 in all the examples you have seen so far we use a single column to uniquely 4826 01:47:18,840 --> 01:47:18,850 we use a single column to uniquely 4827 01:47:18,850 --> 01:47:21,930 we use a single column to uniquely identify the rows in a given table for 4828 01:47:21,930 --> 01:47:21,940 identify the rows in a given table for 4829 01:47:21,940 --> 01:47:24,960 identify the rows in a given table for example in the customers table we have 4830 01:47:24,960 --> 01:47:24,970 example in the customers table we have 4831 01:47:24,970 --> 01:47:27,390 example in the customers table we have this customer ID column which uniquely 4832 01:47:27,390 --> 01:47:27,400 this customer ID column which uniquely 4833 01:47:27,400 --> 01:47:30,240 this customer ID column which uniquely identifies the rows in this table but 4834 01:47:30,240 --> 01:47:30,250 identifies the rows in this table but 4835 01:47:30,250 --> 01:47:31,740 identifies the rows in this table but there are times that we cannot use a 4836 01:47:31,740 --> 01:47:31,750 there are times that we cannot use a 4837 01:47:31,750 --> 01:47:33,690 there are times that we cannot use a single column to uniquely identify 4838 01:47:33,690 --> 01:47:33,700 single column to uniquely identify 4839 01:47:33,700 --> 01:47:36,720 single column to uniquely identify records in a given table for example 4840 01:47:36,720 --> 01:47:36,730 records in a given table for example 4841 01:47:36,730 --> 01:47:40,140 records in a given table for example look at the order items table in this 4842 01:47:40,140 --> 01:47:40,150 look at the order items table in this 4843 01:47:40,150 --> 01:47:41,700 look at the order items table in this table we have columns like order ID 4844 01:47:41,700 --> 01:47:41,710 table we have columns like order ID 4845 01:47:41,710 --> 01:47:44,250 table we have columns like order ID Product ID and so on now if you look at 4846 01:47:44,250 --> 01:47:44,260 Product ID and so on now if you look at 4847 01:47:44,260 --> 01:47:46,470 Product ID and so on now if you look at the data you can see that the values in 4848 01:47:46,470 --> 01:47:46,480 the data you can see that the values in 4849 01:47:46,480 --> 01:47:48,660 the data you can see that the values in the order ID column are repeated or 4850 01:47:48,660 --> 01:47:48,670 the order ID column are repeated or 4851 01:47:48,670 --> 01:47:51,390 the order ID column are repeated or duplicated we have two two two six six 4852 01:47:51,390 --> 01:47:51,400 duplicated we have two two two six six 4853 01:47:51,400 --> 01:47:53,310 duplicated we have two two two six six and so on so we cannot use this column 4854 01:47:53,310 --> 01:47:53,320 and so on so we cannot use this column 4855 01:47:53,320 --> 01:47:55,530 and so on so we cannot use this column on its own to uniquely identify each 4856 01:47:55,530 --> 01:47:55,540 on its own to uniquely identify each 4857 01:47:55,540 --> 01:47:58,050 on its own to uniquely identify each record the same is true for the product 4858 01:47:58,050 --> 01:47:58,060 record the same is true for the product 4859 01:47:58,060 --> 01:48:00,690 record the same is true for the product ID the values in this column are also 4860 01:48:00,690 --> 01:48:00,700 ID the values in this column are also 4861 01:48:00,700 --> 01:48:03,390 ID the values in this column are also duplicated so in this table we use the 4862 01:48:03,390 --> 01:48:03,400 duplicated so in this table we use the 4863 01:48:03,400 --> 01:48:05,880 duplicated so in this table we use the combination of the values in both these 4864 01:48:05,880 --> 01:48:05,890 combination of the values in both these 4865 01:48:05,890 --> 01:48:09,120 combination of the values in both these columns to uniquely identify each order 4866 01:48:09,120 --> 01:48:09,130 columns to uniquely identify each order 4867 01:48:09,130 --> 01:48:12,030 columns to uniquely identify each order item as an example in this order we have 4868 01:48:12,030 --> 01:48:12,040 item as an example in this order we have 4869 01:48:12,040 --> 01:48:15,810 item as an example in this order we have three items for products 1 4 and 6 and 4870 01:48:15,810 --> 01:48:15,820 three items for products 1 4 and 6 and 4871 01:48:15,820 --> 01:48:18,660 three items for products 1 4 and 6 and for each product we have the quantity 4872 01:48:18,660 --> 01:48:18,670 for each product we have the quantity 4873 01:48:18,670 --> 01:48:21,330 for each product we have the quantity and unit price so if we use the 4874 01:48:21,330 --> 01:48:21,340 and unit price so if we use the 4875 01:48:21,340 --> 01:48:23,130 and unit price so if we use the combination of the values in both these 4876 01:48:23,130 --> 01:48:23,140 combination of the values in both these 4877 01:48:23,140 --> 01:48:25,380 combination of the values in both these columns we can uniquely identify each 4878 01:48:25,380 --> 01:48:25,390 columns we can uniquely identify each 4879 01:48:25,390 --> 01:48:28,170 columns we can uniquely identify each order item in other words we don't have 4880 01:48:28,170 --> 01:48:28,180 order item in other words we don't have 4881 01:48:28,180 --> 01:48:31,050 order item in other words we don't have two records for order ID 2 and product 4882 01:48:31,050 --> 01:48:31,060 two records for order ID 2 and product 4883 01:48:31,060 --> 01:48:34,410 two records for order ID 2 and product ID 1 we only have a single record for 4884 01:48:34,410 --> 01:48:34,420 ID 1 we only have a single record for 4885 01:48:34,420 --> 01:48:36,990 ID 1 we only have a single record for that item right now let us open this 4886 01:48:36,990 --> 01:48:37,000 that item right now let us open this 4887 01:48:37,000 --> 01:48:39,480 that item right now let us open this table in the design mode so over here 4888 01:48:39,480 --> 01:48:39,490 table in the design mode so over here 4889 01:48:39,490 --> 01:48:41,430 table in the design mode so over here click on this middle icon that looks 4890 01:48:41,430 --> 01:48:41,440 click on this middle icon that looks 4891 01:48:41,440 --> 01:48:44,430 click on this middle icon that looks like a tool note that this yellow key 4892 01:48:44,430 --> 01:48:44,440 like a tool note that this yellow key 4893 01:48:44,440 --> 01:48:46,590 like a tool note that this yellow key that represents the primary key exists 4894 01:48:46,590 --> 01:48:46,600 that represents the primary key exists 4895 01:48:46,600 --> 01:48:49,050 that represents the primary key exists on both these columns this is what we 4896 01:48:49,050 --> 01:48:49,060 on both these columns this is what we 4897 01:48:49,060 --> 01:48:51,810 on both these columns this is what we call a composite primary key a composite 4898 01:48:51,810 --> 01:48:51,820 call a composite primary key a composite 4899 01:48:51,820 --> 01:48:54,440 call a composite primary key a composite primary key contains more than one color 4900 01:48:54,440 --> 01:48:54,450 primary key contains more than one color 4901 01:48:54,450 --> 01:48:57,540 primary key contains more than one color now why does this matter well what do 4902 01:48:57,540 --> 01:48:57,550 now why does this matter well what do 4903 01:48:57,550 --> 01:48:58,800 now why does this matter well what do you have a table with a composite 4904 01:48:58,800 --> 01:48:58,810 you have a table with a composite 4905 01:48:58,810 --> 01:49:00,900 you have a table with a composite primary key you need to learn how to 4906 01:49:00,900 --> 01:49:00,910 primary key you need to learn how to 4907 01:49:00,910 --> 01:49:03,600 primary key you need to learn how to join that table with other tables for 4908 01:49:03,600 --> 01:49:03,610 join that table with other tables for 4909 01:49:03,610 --> 01:49:05,940 join that table with other tables for example here we have this table order 4910 01:49:05,940 --> 01:49:05,950 example here we have this table order 4911 01:49:05,950 --> 01:49:08,880 example here we have this table order item notes that we use to keep notes for 4912 01:49:08,880 --> 01:49:08,890 item notes that we use to keep notes for 4913 01:49:08,890 --> 01:49:11,220 item notes that we use to keep notes for each order item let's take a look at the 4914 01:49:11,220 --> 01:49:11,230 each order item let's take a look at the 4915 01:49:11,230 --> 01:49:13,950 each order item let's take a look at the data here so we have this column note ID 4916 01:49:13,950 --> 01:49:13,960 data here so we have this column note ID 4917 01:49:13,960 --> 01:49:16,440 data here so we have this column note ID which uniquely identifies the records in 4918 01:49:16,440 --> 01:49:16,450 which uniquely identifies the records in 4919 01:49:16,450 --> 01:49:19,230 which uniquely identifies the records in this table next to that we have order ID 4920 01:49:19,230 --> 01:49:19,240 this table next to that we have order ID 4921 01:49:19,240 --> 01:49:21,360 this table next to that we have order ID and Product ID you learn that the 4922 01:49:21,360 --> 01:49:21,370 and Product ID you learn that the 4923 01:49:21,370 --> 01:49:23,310 and Product ID you learn that the combination of these two columns you 4924 01:49:23,310 --> 01:49:23,320 combination of these two columns you 4925 01:49:23,320 --> 01:49:26,669 combination of these two columns you nuclear represent and order item so here 4926 01:49:26,669 --> 01:49:26,679 nuclear represent and order item so here 4927 01:49:26,679 --> 01:49:28,800 nuclear represent and order item so here for order number two for product number 4928 01:49:28,800 --> 01:49:28,810 for order number two for product number 4929 01:49:28,810 --> 01:49:31,890 for order number two for product number one we have two notes now let me show 4930 01:49:31,890 --> 01:49:31,900 one we have two notes now let me show 4931 01:49:31,900 --> 01:49:33,750 one we have two notes now let me show you how to join this table with the 4932 01:49:33,750 --> 01:49:33,760 you how to join this table with the 4933 01:49:33,760 --> 01:49:36,680 you how to join this table with the order items table so back to our query 4934 01:49:36,680 --> 01:49:36,690 order items table so back to our query 4935 01:49:36,690 --> 01:49:38,970 order items table so back to our query you can see that I've already selected 4936 01:49:38,970 --> 01:49:38,980 you can see that I've already selected 4937 01:49:38,980 --> 01:49:41,189 you can see that I've already selected the sequel store database so i'm not 4938 01:49:41,189 --> 01:49:41,199 the sequel store database so i'm not 4939 01:49:41,199 --> 01:49:42,899 the sequel store database so i'm not gonna type out a use statement 4940 01:49:42,899 --> 01:49:42,909 gonna type out a use statement 4941 01:49:42,909 --> 01:49:47,310 gonna type out a use statement alright let's select everything from the 4942 01:49:47,310 --> 01:49:47,320 alright let's select everything from the 4943 01:49:47,320 --> 01:49:51,750 alright let's select everything from the order items table give it an alias now 4944 01:49:51,750 --> 01:49:51,760 order items table give it an alias now 4945 01:49:51,760 --> 01:49:54,540 order items table give it an alias now we need to join this with order item 4946 01:49:54,540 --> 01:49:54,550 we need to join this with order item 4947 01:49:54,550 --> 01:49:58,859 we need to join this with order item notes also we're giving an alias how are 4948 01:49:58,859 --> 01:49:58,869 notes also we're giving an alias how are 4949 01:49:58,869 --> 01:50:00,959 notes also we're giving an alias how are we going to join these tables based on 4950 01:50:00,959 --> 01:50:00,969 we going to join these tables based on 4951 01:50:00,969 --> 01:50:03,450 we going to join these tables based on two columns back to the order items 4952 01:50:03,450 --> 01:50:03,460 two columns back to the order items 4953 01:50:03,460 --> 01:50:06,300 two columns back to the order items table these are the columns that we need 4954 01:50:06,300 --> 01:50:06,310 table these are the columns that we need 4955 01:50:06,310 --> 01:50:10,229 table these are the columns that we need to use in our joint condition so in the 4956 01:50:10,229 --> 01:50:10,239 to use in our joint condition so in the 4957 01:50:10,239 --> 01:50:13,680 to use in our joint condition so in the order items table we have this order ID 4958 01:50:13,680 --> 01:50:13,690 order items table we have this order ID 4959 01:50:13,690 --> 01:50:16,500 order items table we have this order ID column this would be equal to the same 4960 01:50:16,500 --> 01:50:16,510 column this would be equal to the same 4961 01:50:16,510 --> 01:50:20,189 column this would be equal to the same column in order item note table so oh I 4962 01:50:20,189 --> 01:50:20,199 column in order item note table so oh I 4963 01:50:20,199 --> 01:50:24,300 column in order item note table so oh I am dot order ID but this is not enough 4964 01:50:24,300 --> 01:50:24,310 am dot order ID but this is not enough 4965 01:50:24,310 --> 01:50:26,819 am dot order ID but this is not enough we should also join these tables based 4966 01:50:26,819 --> 01:50:26,829 we should also join these tables based 4967 01:50:26,829 --> 01:50:30,030 we should also join these tables based on the product ID column so we type out 4968 01:50:30,030 --> 01:50:30,040 on the product ID column so we type out 4969 01:50:30,040 --> 01:50:32,399 on the product ID column so we type out and and then we type out our second 4970 01:50:32,399 --> 01:50:32,409 and and then we type out our second 4971 01:50:32,409 --> 01:50:36,149 and and then we type out our second condition so order items dot product ID 4972 01:50:36,149 --> 01:50:36,159 condition so order items dot product ID 4973 01:50:36,159 --> 01:50:39,180 condition so order items dot product ID should be equal to order item notes dot 4974 01:50:39,180 --> 01:50:39,190 should be equal to order item notes dot 4975 01:50:39,190 --> 01:50:42,629 should be equal to order item notes dot product ID this is what we call a 4976 01:50:42,629 --> 01:50:42,639 product ID this is what we call a 4977 01:50:42,639 --> 01:50:45,990 product ID this is what we call a compound join condition so we have 4978 01:50:45,990 --> 01:50:46,000 compound join condition so we have 4979 01:50:46,000 --> 01:50:48,209 compound join condition so we have multiple conditions to join these two 4980 01:50:48,209 --> 01:50:48,219 multiple conditions to join these two 4981 01:50:48,219 --> 01:50:54,500 multiple conditions to join these two tables 4982 01:50:54,500 --> 01:50:54,510 4983 01:50:54,510 --> 01:50:57,030 in this tutorial I'm going to talk about 4984 01:50:57,030 --> 01:50:57,040 in this tutorial I'm going to talk about 4985 01:50:57,040 --> 01:51:00,840 in this tutorial I'm going to talk about the implicit join syntax in MySQL so 4986 01:51:00,840 --> 01:51:00,850 the implicit join syntax in MySQL so 4987 01:51:00,850 --> 01:51:03,030 the implicit join syntax in MySQL so here we have a basic inner join we're 4988 01:51:03,030 --> 01:51:03,040 here we have a basic inner join we're 4989 01:51:03,040 --> 01:51:04,320 here we have a basic inner join we're selecting everything from the orders 4990 01:51:04,320 --> 01:51:04,330 selecting everything from the orders 4991 01:51:04,330 --> 01:51:06,720 selecting everything from the orders table joining it with customers table on 4992 01:51:06,720 --> 01:51:06,730 table joining it with customers table on 4993 01:51:06,730 --> 01:51:09,420 table joining it with customers table on orders the customer ID equal to 4994 01:51:09,420 --> 01:51:09,430 orders the customer ID equal to 4995 01:51:09,430 --> 01:51:12,959 orders the customer ID equal to customers customer ID pretty basic there 4996 01:51:12,959 --> 01:51:12,969 customers customer ID pretty basic there 4997 01:51:12,969 --> 01:51:15,270 customers customer ID pretty basic there is another way to write this query using 4998 01:51:15,270 --> 01:51:15,280 is another way to write this query using 4999 01:51:15,280 --> 01:51:18,060 is another way to write this query using implicit join syntax let me show you how 5000 01:51:18,060 --> 01:51:18,070 implicit join syntax let me show you how 5001 01:51:18,070 --> 01:51:25,080 implicit join syntax let me show you how that works so we select everything from 5002 01:51:25,080 --> 01:51:25,090 that works so we select everything from 5003 01:51:25,090 --> 01:51:27,900 that works so we select everything from here we can type out multiple table 5004 01:51:27,900 --> 01:51:27,910 here we can type out multiple table 5005 01:51:27,910 --> 01:51:32,700 here we can type out multiple table names so orders comma customers and we 5006 01:51:32,700 --> 01:51:32,710 names so orders comma customers and we 5007 01:51:32,710 --> 01:51:34,380 names so orders comma customers and we can also give them an alias 5008 01:51:34,380 --> 01:51:34,390 can also give them an alias 5009 01:51:34,390 --> 01:51:39,600 can also give them an alias so C and O and then we move this joint 5010 01:51:39,600 --> 01:51:39,610 so C and O and then we move this joint 5011 01:51:39,610 --> 01:51:42,120 so C and O and then we move this joint condition to the where clause so I'm 5012 01:51:42,120 --> 01:51:42,130 condition to the where clause so I'm 5013 01:51:42,130 --> 01:51:44,640 condition to the where clause so I'm going to copy this from here type out a 5014 01:51:44,640 --> 01:51:44,650 going to copy this from here type out a 5015 01:51:44,650 --> 01:51:46,670 going to copy this from here type out a where clause and paste the condition 5016 01:51:46,670 --> 01:51:46,680 where clause and paste the condition 5017 01:51:46,680 --> 01:51:50,250 where clause and paste the condition these two queries are equivalent what we 5018 01:51:50,250 --> 01:51:50,260 these two queries are equivalent what we 5019 01:51:50,260 --> 01:51:53,700 these two queries are equivalent what we have here is called implicit join syntax 5020 01:51:53,700 --> 01:51:53,710 have here is called implicit join syntax 5021 01:51:53,710 --> 01:51:55,920 have here is called implicit join syntax now even though MySQL supports the 5022 01:51:55,920 --> 01:51:55,930 now even though MySQL supports the 5023 01:51:55,930 --> 01:51:57,780 now even though MySQL supports the syntax it's something that I suggest you 5024 01:51:57,780 --> 01:51:57,790 syntax it's something that I suggest you 5025 01:51:57,790 --> 01:51:59,850 syntax it's something that I suggest you not to use because if you accidentally 5026 01:51:59,850 --> 01:51:59,860 not to use because if you accidentally 5027 01:51:59,860 --> 01:52:02,040 not to use because if you accidentally forget to type out the where clause you 5028 01:52:02,040 --> 01:52:02,050 forget to type out the where clause you 5029 01:52:02,050 --> 01:52:04,680 forget to type out the where clause you will get a cross join let me show you 5030 01:52:04,680 --> 01:52:04,690 will get a cross join let me show you 5031 01:52:04,690 --> 01:52:06,450 will get a cross join let me show you what I mean so first I'm gonna delete 5032 01:52:06,450 --> 01:52:06,460 what I mean so first I'm gonna delete 5033 01:52:06,460 --> 01:52:14,160 what I mean so first I'm gonna delete the first query and execute this so we 5034 01:52:14,160 --> 01:52:14,170 the first query and execute this so we 5035 01:52:14,170 --> 01:52:16,740 the first query and execute this so we get 10 records because we have 10 orders 5036 01:52:16,740 --> 01:52:16,750 get 10 records because we have 10 orders 5037 01:52:16,750 --> 01:52:19,979 get 10 records because we have 10 orders in this database so far so good but what 5038 01:52:19,979 --> 01:52:19,989 in this database so far so good but what 5039 01:52:19,989 --> 01:52:23,400 in this database so far so good but what happens if you accidentally forget to 5040 01:52:23,400 --> 01:52:23,410 happens if you accidentally forget to 5041 01:52:23,410 --> 01:52:27,630 happens if you accidentally forget to type out the where clause instead of 10 5042 01:52:27,630 --> 01:52:27,640 type out the where clause instead of 10 5043 01:52:27,640 --> 01:52:29,760 type out the where clause instead of 10 records we're gonna get probably 100 5044 01:52:29,760 --> 01:52:29,770 records we're gonna get probably 100 5045 01:52:29,770 --> 01:52:32,790 records we're gonna get probably 100 records because every record in the 5046 01:52:32,790 --> 01:52:32,800 records because every record in the 5047 01:52:32,800 --> 01:52:35,370 records because every record in the order table is now joined with every 5048 01:52:35,370 --> 01:52:35,380 order table is now joined with every 5049 01:52:35,380 --> 01:52:38,190 order table is now joined with every record in the customers table this is 5050 01:52:38,190 --> 01:52:38,200 record in the customers table this is 5051 01:52:38,200 --> 01:52:40,320 record in the customers table this is what we call a cross string now later in 5052 01:52:40,320 --> 01:52:40,330 what we call a cross string now later in 5053 01:52:40,330 --> 01:52:41,700 what we call a cross string now later in this section I'm gonna talk about cross 5054 01:52:41,700 --> 01:52:41,710 this section I'm gonna talk about cross 5055 01:52:41,710 --> 01:52:43,680 this section I'm gonna talk about cross joins in more detail but what I want to 5056 01:52:43,680 --> 01:52:43,690 joins in more detail but what I want to 5057 01:52:43,690 --> 01:52:46,320 joins in more detail but what I want to point out in this tutorial is that it's 5058 01:52:46,320 --> 01:52:46,330 point out in this tutorial is that it's 5059 01:52:46,330 --> 01:52:48,990 point out in this tutorial is that it's better to use the explicit join syntax 5060 01:52:48,990 --> 01:52:49,000 better to use the explicit join syntax 5061 01:52:49,000 --> 01:52:52,709 better to use the explicit join syntax so we use join because this syntax 5062 01:52:52,709 --> 01:52:52,719 so we use join because this syntax 5063 01:52:52,719 --> 01:52:54,990 so we use join because this syntax forces you to type out the joint 5064 01:52:54,990 --> 01:52:55,000 forces you to type out the joint 5065 01:52:55,000 --> 01:52:57,990 forces you to type out the joint condition if you simply join orders with 5066 01:52:57,990 --> 01:52:58,000 condition if you simply join orders with 5067 01:52:58,000 --> 01:53:00,690 condition if you simply join orders with customers without typing the join 5068 01:53:00,690 --> 01:53:00,700 customers without typing the join 5069 01:53:00,700 --> 01:53:02,520 customers without typing the join condition you're gonna get a syntax 5070 01:53:02,520 --> 01:53:02,530 condition you're gonna get a syntax 5071 01:53:02,530 --> 01:53:04,620 condition you're gonna get a syntax error so to recap 5072 01:53:04,620 --> 01:53:04,630 error so to recap 5073 01:53:04,630 --> 01:53:07,530 error so to recap be aware of the implicit join syntax but 5074 01:53:07,530 --> 01:53:07,540 be aware of the implicit join syntax but 5075 01:53:07,540 --> 01:53:09,510 be aware of the implicit join syntax but write all your joints using the explicit 5076 01:53:09,510 --> 01:53:09,520 write all your joints using the explicit 5077 01:53:09,520 --> 01:53:15,700 write all your joints using the explicit syntax 5078 01:53:15,700 --> 01:53:15,710 5079 01:53:15,710 --> 01:53:17,930 earlier in this section I told you that 5080 01:53:17,930 --> 01:53:17,940 earlier in this section I told you that 5081 01:53:17,940 --> 01:53:19,910 earlier in this section I told you that in sequel we have two types of joints 5082 01:53:19,910 --> 01:53:19,920 in sequel we have two types of joints 5083 01:53:19,920 --> 01:53:23,420 in sequel we have two types of joints inner joins and outer joins that's so 5084 01:53:23,420 --> 01:53:23,430 inner joins and outer joins that's so 5085 01:53:23,430 --> 01:53:25,370 inner joins and outer joins that's so far you have only seen examples of inner 5086 01:53:25,370 --> 01:53:25,380 far you have only seen examples of inner 5087 01:53:25,380 --> 01:53:27,230 far you have only seen examples of inner joins and I also told you that this 5088 01:53:27,230 --> 01:53:27,240 joins and I also told you that this 5089 01:53:27,240 --> 01:53:29,720 joins and I also told you that this inner keyword is optional so whenever 5090 01:53:29,720 --> 01:53:29,730 inner keyword is optional so whenever 5091 01:53:29,730 --> 01:53:32,060 inner keyword is optional so whenever you type out a join you're using an 5092 01:53:32,060 --> 01:53:32,070 you type out a join you're using an 5093 01:53:32,070 --> 01:53:33,830 you type out a join you're using an inner join in this tutorial we're going 5094 01:53:33,830 --> 01:53:33,840 inner join in this tutorial we're going 5095 01:53:33,840 --> 01:53:36,080 inner join in this tutorial we're going to look at outer joins and the problems 5096 01:53:36,080 --> 01:53:36,090 to look at outer joins and the problems 5097 01:53:36,090 --> 01:53:39,230 to look at outer joins and the problems they solve so let's start by writing a 5098 01:53:39,230 --> 01:53:39,240 they solve so let's start by writing a 5099 01:53:39,240 --> 01:53:41,540 they solve so let's start by writing a query that uses an inner join and then 5100 01:53:41,540 --> 01:53:41,550 query that uses an inner join and then 5101 01:53:41,550 --> 01:53:42,980 query that uses an inner join and then we'll convert that inner join to an 5102 01:53:42,980 --> 01:53:42,990 we'll convert that inner join to an 5103 01:53:42,990 --> 01:53:43,730 we'll convert that inner join to an outer join 5104 01:53:43,730 --> 01:53:43,740 outer join 5105 01:53:43,740 --> 01:53:48,170 outer join so select everything from the customers 5106 01:53:48,170 --> 01:53:48,180 so select everything from the customers 5107 01:53:48,180 --> 01:53:52,870 so select everything from the customers table join it with the orders table on 5108 01:53:52,870 --> 01:53:52,880 table join it with the orders table on 5109 01:53:52,880 --> 01:53:55,850 table join it with the orders table on see that customer ID should be equal to 5110 01:53:55,850 --> 01:53:55,860 see that customer ID should be equal to 5111 01:53:55,860 --> 01:54:00,800 see that customer ID should be equal to oh that customer ID pretty basic right 5112 01:54:00,800 --> 01:54:00,810 oh that customer ID pretty basic right 5113 01:54:00,810 --> 01:54:03,740 oh that customer ID pretty basic right now for clarity let's pick a few columns 5114 01:54:03,740 --> 01:54:03,750 now for clarity let's pick a few columns 5115 01:54:03,750 --> 01:54:05,870 now for clarity let's pick a few columns from these two tables so from the 5116 01:54:05,870 --> 01:54:05,880 from these two tables so from the 5117 01:54:05,880 --> 01:54:08,450 from these two tables so from the customers table I want to pick customer 5118 01:54:08,450 --> 01:54:08,460 customers table I want to pick customer 5119 01:54:08,460 --> 01:54:14,000 customers table I want to pick customer ID and first name and from the orders 5120 01:54:14,000 --> 01:54:14,010 ID and first name and from the orders 5121 01:54:14,010 --> 01:54:17,150 ID and first name and from the orders table I want to pick order ID now 5122 01:54:17,150 --> 01:54:17,160 table I want to pick order ID now 5123 01:54:17,160 --> 01:54:19,400 table I want to pick order ID now finally let's sort the result so we can 5124 01:54:19,400 --> 01:54:19,410 finally let's sort the result so we can 5125 01:54:19,410 --> 01:54:22,430 finally let's sort the result so we can clearly see what we get so order by see 5126 01:54:22,430 --> 01:54:22,440 clearly see what we get so order by see 5127 01:54:22,440 --> 01:54:25,910 clearly see what we get so order by see that customer ID let's execute this 5128 01:54:25,910 --> 01:54:25,920 that customer ID let's execute this 5129 01:54:25,920 --> 01:54:29,450 that customer ID let's execute this query and see what we get so here's the 5130 01:54:29,450 --> 01:54:29,460 query and see what we get so here's the 5131 01:54:29,460 --> 01:54:32,540 query and see what we get so here's the result for customer number two called 5132 01:54:32,540 --> 01:54:32,550 result for customer number two called 5133 01:54:32,550 --> 01:54:35,570 result for customer number two called anus or Ines whatever we have two orders 5134 01:54:35,570 --> 01:54:35,580 anus or Ines whatever we have two orders 5135 01:54:35,580 --> 01:54:38,720 anus or Ines whatever we have two orders order for and order seven similarly for 5136 01:54:38,720 --> 01:54:38,730 order for and order seven similarly for 5137 01:54:38,730 --> 01:54:41,000 order for and order seven similarly for customer number five we have two orders 5138 01:54:41,000 --> 01:54:41,010 customer number five we have two orders 5139 01:54:41,010 --> 01:54:43,160 customer number five we have two orders and so on now there is something missing 5140 01:54:43,160 --> 01:54:43,170 and so on now there is something missing 5141 01:54:43,170 --> 01:54:45,980 and so on now there is something missing in this result we only see customers who 5142 01:54:45,980 --> 01:54:45,990 in this result we only see customers who 5143 01:54:45,990 --> 01:54:48,200 in this result we only see customers who have an order in our system these are 5144 01:54:48,200 --> 01:54:48,210 have an order in our system these are 5145 01:54:48,210 --> 01:54:51,110 have an order in our system these are customers two five six seven eight and 5146 01:54:51,110 --> 01:54:51,120 customers two five six seven eight and 5147 01:54:51,120 --> 01:54:53,450 customers two five six seven eight and ten but if you look at the customers 5148 01:54:53,450 --> 01:54:53,460 ten but if you look at the customers 5149 01:54:53,460 --> 01:54:56,120 ten but if you look at the customers table you can see that we have other 5150 01:54:56,120 --> 01:54:56,130 table you can see that we have other 5151 01:54:56,130 --> 01:54:57,650 table you can see that we have other customers like customer number one 5152 01:54:57,650 --> 01:54:57,660 customers like customer number one 5153 01:54:57,660 --> 01:54:59,990 customers like customer number one customer number three and so on now 5154 01:54:59,990 --> 01:55:00,000 customer number three and so on now 5155 01:55:00,000 --> 01:55:01,760 customer number three and so on now currently we don't have any orders for 5156 01:55:01,760 --> 01:55:01,770 currently we don't have any orders for 5157 01:55:01,770 --> 01:55:04,280 currently we don't have any orders for these customers and that's the reason we 5158 01:55:04,280 --> 01:55:04,290 these customers and that's the reason we 5159 01:55:04,290 --> 01:55:06,920 these customers and that's the reason we don't see them in this result set but 5160 01:55:06,920 --> 01:55:06,930 don't see them in this result set but 5161 01:55:06,930 --> 01:55:08,090 don't see them in this result set but what if you want to see all the 5162 01:55:08,090 --> 01:55:08,100 what if you want to see all the 5163 01:55:08,100 --> 01:55:10,250 what if you want to see all the customers whether they have an order or 5164 01:55:10,250 --> 01:55:10,260 customers whether they have an order or 5165 01:55:10,260 --> 01:55:12,680 customers whether they have an order or not that's when we use an outer join 5166 01:55:12,680 --> 01:55:12,690 not that's when we use an outer join 5167 01:55:12,690 --> 01:55:14,990 not that's when we use an outer join let me show you how that works so back 5168 01:55:14,990 --> 01:55:15,000 let me show you how that works so back 5169 01:55:15,000 --> 01:55:17,780 let me show you how that works so back to our query the reason we only saw 5170 01:55:17,780 --> 01:55:17,790 to our query the reason we only saw 5171 01:55:17,790 --> 01:55:20,060 to our query the reason we only saw customers who have an order was because 5172 01:55:20,060 --> 01:55:20,070 customers who have an order was because 5173 01:55:20,070 --> 01:55:22,700 customers who have an order was because of this join condition when joining 5174 01:55:22,700 --> 01:55:22,710 of this join condition when joining 5175 01:55:22,710 --> 01:55:24,950 of this join condition when joining these two tables we are only returning 5176 01:55:24,950 --> 01:55:24,960 these two tables we are only returning 5177 01:55:24,960 --> 01:55:28,550 these two tables we are only returning words that match this condition so for a 5178 01:55:28,550 --> 01:55:28,560 words that match this condition so for a 5179 01:55:28,560 --> 01:55:30,740 words that match this condition so for a given customer if we do have an order 5180 01:55:30,740 --> 01:55:30,750 given customer if we do have an order 5181 01:55:30,750 --> 01:55:33,770 given customer if we do have an order that record is returned but as you saw a 5182 01:55:33,770 --> 01:55:33,780 that record is returned but as you saw a 5183 01:55:33,780 --> 01:55:36,050 that record is returned but as you saw a second ago some of our customers don't 5184 01:55:36,050 --> 01:55:36,060 second ago some of our customers don't 5185 01:55:36,060 --> 01:55:38,180 second ago some of our customers don't have an order so for those customers 5186 01:55:38,180 --> 01:55:38,190 have an order so for those customers 5187 01:55:38,190 --> 01:55:41,390 have an order so for those customers this condition is not valid and that is 5188 01:55:41,390 --> 01:55:41,400 this condition is not valid and that is 5189 01:55:41,400 --> 01:55:43,040 this condition is not valid and that is the reason they are not returned in the 5190 01:55:43,040 --> 01:55:43,050 the reason they are not returned in the 5191 01:55:43,050 --> 01:55:43,790 the reason they are not returned in the result set 5192 01:55:43,790 --> 01:55:43,800 result set 5193 01:55:43,800 --> 01:55:46,070 result set to solve this problem we use an outer 5194 01:55:46,070 --> 01:55:46,080 to solve this problem we use an outer 5195 01:55:46,080 --> 01:55:49,130 to solve this problem we use an outer join now in sequel we have two types of 5196 01:55:49,130 --> 01:55:49,140 join now in sequel we have two types of 5197 01:55:49,140 --> 01:55:51,490 join now in sequel we have two types of outer joins we have left joints and 5198 01:55:51,490 --> 01:55:51,500 outer joins we have left joints and 5199 01:55:51,500 --> 01:55:55,880 outer joins we have left joints and right joints when we use a left join all 5200 01:55:55,880 --> 01:55:55,890 right joints when we use a left join all 5201 01:55:55,890 --> 01:55:58,760 right joints when we use a left join all the records from the left table in this 5202 01:55:58,760 --> 01:55:58,770 the records from the left table in this 5203 01:55:58,770 --> 01:56:01,520 the records from the left table in this case customers are returned whether this 5204 01:56:01,520 --> 01:56:01,530 case customers are returned whether this 5205 01:56:01,530 --> 01:56:04,370 case customers are returned whether this condition is true or not so we get all 5206 01:56:04,370 --> 01:56:04,380 condition is true or not so we get all 5207 01:56:04,380 --> 01:56:06,290 condition is true or not so we get all the customers and if they do have an 5208 01:56:06,290 --> 01:56:06,300 the customers and if they do have an 5209 01:56:06,300 --> 01:56:08,270 the customers and if they do have an order we'll see the order ID as well 5210 01:56:08,270 --> 01:56:08,280 order we'll see the order ID as well 5211 01:56:08,280 --> 01:56:10,640 order we'll see the order ID as well let's execute this query and see what we 5212 01:56:10,640 --> 01:56:10,650 let's execute this query and see what we 5213 01:56:10,650 --> 01:56:11,560 let's execute this query and see what we get 5214 01:56:11,560 --> 01:56:11,570 get 5215 01:56:11,570 --> 01:56:16,340 get so there you go customer number one 5216 01:56:16,340 --> 01:56:16,350 so there you go customer number one 5217 01:56:16,350 --> 01:56:18,620 so there you go customer number one doesn't have an order and that's why we 5218 01:56:18,620 --> 01:56:18,630 doesn't have an order and that's why we 5219 01:56:18,630 --> 01:56:21,500 doesn't have an order and that's why we get null in this cell customer number 5220 01:56:21,500 --> 01:56:21,510 get null in this cell customer number 5221 01:56:21,510 --> 01:56:23,690 get null in this cell customer number two has two orders four and seven 5222 01:56:23,690 --> 01:56:23,700 two has two orders four and seven 5223 01:56:23,700 --> 01:56:25,820 two has two orders four and seven customer number three also doesn't have 5224 01:56:25,820 --> 01:56:25,830 customer number three also doesn't have 5225 01:56:25,830 --> 01:56:28,090 customer number three also doesn't have an order so we have null for order ID 5226 01:56:28,090 --> 01:56:28,100 an order so we have null for order ID 5227 01:56:28,100 --> 01:56:31,490 an order so we have null for order ID this is the result of a left joint so 5228 01:56:31,490 --> 01:56:31,500 this is the result of a left joint so 5229 01:56:31,500 --> 01:56:33,560 this is the result of a left joint so back to our query when we use a left 5230 01:56:33,560 --> 01:56:33,570 back to our query when we use a left 5231 01:56:33,570 --> 01:56:36,440 back to our query when we use a left join all the records from the left table 5232 01:56:36,440 --> 01:56:36,450 join all the records from the left table 5233 01:56:36,450 --> 01:56:38,660 join all the records from the left table are returned whether this condition is 5234 01:56:38,660 --> 01:56:38,670 are returned whether this condition is 5235 01:56:38,670 --> 01:56:41,900 are returned whether this condition is true or not now what if we use a right 5236 01:56:41,900 --> 01:56:41,910 true or not now what if we use a right 5237 01:56:41,910 --> 01:56:45,650 true or not now what if we use a right joint in this case all the records from 5238 01:56:45,650 --> 01:56:45,660 joint in this case all the records from 5239 01:56:45,660 --> 01:56:47,570 joint in this case all the records from the orders table are returned whether 5240 01:56:47,570 --> 01:56:47,580 the orders table are returned whether 5241 01:56:47,580 --> 01:56:49,640 the orders table are returned whether this condition is true or not let's 5242 01:56:49,640 --> 01:56:49,650 this condition is true or not let's 5243 01:56:49,650 --> 01:56:51,970 this condition is true or not let's execute this query and see what we get 5244 01:56:51,970 --> 01:56:51,980 execute this query and see what we get 5245 01:56:51,980 --> 01:56:56,300 execute this query and see what we get so we get the same result as before when 5246 01:56:56,300 --> 01:56:56,310 so we get the same result as before when 5247 01:56:56,310 --> 01:56:58,040 so we get the same result as before when we use an inner join because we're 5248 01:56:58,040 --> 01:56:58,050 we use an inner join because we're 5249 01:56:58,050 --> 01:56:59,959 we use an inner join because we're selecting all the records from the right 5250 01:56:59,959 --> 01:56:59,969 selecting all the records from the right 5251 01:56:59,969 --> 01:57:02,780 selecting all the records from the right table which is the orders table so we 5252 01:57:02,780 --> 01:57:02,790 table which is the orders table so we 5253 01:57:02,790 --> 01:57:04,640 table which is the orders table so we don't see all the customers we see all 5254 01:57:04,640 --> 01:57:04,650 don't see all the customers we see all 5255 01:57:04,650 --> 01:57:07,040 don't see all the customers we see all the orders right now if you want to use 5256 01:57:07,040 --> 01:57:07,050 the orders right now if you want to use 5257 01:57:07,050 --> 01:57:08,780 the orders right now if you want to use a right join and still see all the 5258 01:57:08,780 --> 01:57:08,790 a right join and still see all the 5259 01:57:08,790 --> 01:57:11,150 a right join and still see all the customers you need to swap the order of 5260 01:57:11,150 --> 01:57:11,160 customers you need to swap the order of 5261 01:57:11,160 --> 01:57:14,450 customers you need to swap the order of these tables so we put the orders table 5262 01:57:14,450 --> 01:57:14,460 these tables so we put the orders table 5263 01:57:14,460 --> 01:57:16,820 these tables so we put the orders table first that's gonna be our left table and 5264 01:57:16,820 --> 01:57:16,830 first that's gonna be our left table and 5265 01:57:16,830 --> 01:57:19,729 first that's gonna be our left table and then we put the customers on the right 5266 01:57:19,729 --> 01:57:19,739 then we put the customers on the right 5267 01:57:19,739 --> 01:57:21,709 then we put the customers on the right side so now with this query will return 5268 01:57:21,709 --> 01:57:21,719 side so now with this query will return 5269 01:57:21,719 --> 01:57:23,990 side so now with this query will return all the records from the right table 5270 01:57:23,990 --> 01:57:24,000 all the records from the right table 5271 01:57:24,000 --> 01:57:26,600 all the records from the right table which is the customers table let me 5272 01:57:26,600 --> 01:57:26,610 which is the customers table let me 5273 01:57:26,610 --> 01:57:30,170 which is the customers table let me execute this we get all the customers 5274 01:57:30,170 --> 01:57:30,180 execute this we get all the customers 5275 01:57:30,180 --> 01:57:31,970 execute this we get all the customers whether they have an order or not 5276 01:57:31,970 --> 01:57:31,980 whether they have an order or not 5277 01:57:31,980 --> 01:57:35,360 whether they have an order or not beautiful now one last thing we finish 5278 01:57:35,360 --> 01:57:35,370 beautiful now one last thing we finish 5279 01:57:35,370 --> 01:57:37,580 beautiful now one last thing we finish this tutorial I've seen developers use 5280 01:57:37,580 --> 01:57:37,590 this tutorial I've seen developers use 5281 01:57:37,590 --> 01:57:38,750 this tutorial I've seen developers use the outer keyword 5282 01:57:38,750 --> 01:57:38,760 the outer keyword 5283 01:57:38,760 --> 01:57:42,200 the outer keyword so either right outer join or left outer 5284 01:57:42,200 --> 01:57:42,210 so either right outer join or left outer 5285 01:57:42,210 --> 01:57:44,810 so either right outer join or left outer join but technically the outer keyword 5286 01:57:44,810 --> 01:57:44,820 join but technically the outer keyword 5287 01:57:44,820 --> 01:57:46,940 join but technically the outer keyword is optional just like the inner keyword 5288 01:57:46,940 --> 01:57:46,950 is optional just like the inner keyword 5289 01:57:46,950 --> 01:57:49,370 is optional just like the inner keyword so you don't have to type it out so I'm 5290 01:57:49,370 --> 01:57:49,380 so you don't have to type it out so I'm 5291 01:57:49,380 --> 01:57:50,570 so you don't have to type it out so I'm gonna remove this to make my code 5292 01:57:50,570 --> 01:57:50,580 gonna remove this to make my code 5293 01:57:50,580 --> 01:57:52,580 gonna remove this to make my code shorter and easier to understand 5294 01:57:52,580 --> 01:57:52,590 shorter and easier to understand 5295 01:57:52,590 --> 01:57:54,920 shorter and easier to understand so to recap if you use the join keyword 5296 01:57:54,920 --> 01:57:54,930 so to recap if you use the join keyword 5297 01:57:54,930 --> 01:57:57,350 so to recap if you use the join keyword you're doing an inner join and if you do 5298 01:57:57,350 --> 01:57:57,360 you're doing an inner join and if you do 5299 01:57:57,360 --> 01:58:00,200 you're doing an inner join and if you do a left or right join you're doing an 5300 01:58:00,200 --> 01:58:00,210 a left or right join you're doing an 5301 01:58:00,210 --> 01:58:04,800 a left or right join you're doing an outer join 5302 01:58:04,800 --> 01:58:04,810 5303 01:58:04,810 --> 01:58:07,330 here's our exercise for this tutorial I 5304 01:58:07,330 --> 01:58:07,340 here's our exercise for this tutorial I 5305 01:58:07,340 --> 01:58:09,610 here's our exercise for this tutorial I want you to write a query that produces 5306 01:58:09,610 --> 01:58:09,620 want you to write a query that produces 5307 01:58:09,620 --> 01:58:11,410 want you to write a query that produces this result so we have three columns 5308 01:58:11,410 --> 01:58:11,420 this result so we have three columns 5309 01:58:11,420 --> 01:58:15,160 this result so we have three columns here product ID name and quantity that I 5310 01:58:15,160 --> 01:58:15,170 here product ID name and quantity that I 5311 01:58:15,170 --> 01:58:17,770 here product ID name and quantity that I picked from the order items table so 5312 01:58:17,770 --> 01:58:17,780 picked from the order items table so 5313 01:58:17,780 --> 01:58:19,510 picked from the order items table so here we need to join the products table 5314 01:58:19,510 --> 01:58:19,520 here we need to join the products table 5315 01:58:19,520 --> 01:58:22,360 here we need to join the products table with order items table so we can see how 5316 01:58:22,360 --> 01:58:22,370 with order items table so we can see how 5317 01:58:22,370 --> 01:58:24,340 with order items table so we can see how many times each product is ordered 5318 01:58:24,340 --> 01:58:24,350 many times each product is ordered 5319 01:58:24,350 --> 01:58:26,710 many times each product is ordered however if we do an inner join 5320 01:58:26,710 --> 01:58:26,720 however if we do an inner join 5321 01:58:26,720 --> 01:58:28,300 however if we do an inner join we'll only see the products that have 5322 01:58:28,300 --> 01:58:28,310 we'll only see the products that have 5323 01:58:28,310 --> 01:58:30,100 we'll only see the products that have been ordered but here I'm doing an outer 5324 01:58:30,100 --> 01:58:30,110 been ordered but here I'm doing an outer 5325 01:58:30,110 --> 01:58:33,460 been ordered but here I'm doing an outer join so product number seven has never 5326 01:58:33,460 --> 01:58:33,470 join so product number seven has never 5327 01:58:33,470 --> 01:58:35,530 join so product number seven has never been ordered but still exists in the 5328 01:58:35,530 --> 01:58:35,540 been ordered but still exists in the 5329 01:58:35,540 --> 01:58:39,130 been ordered but still exists in the result we see no for the quantity so go 5330 01:58:39,130 --> 01:58:39,140 result we see no for the quantity so go 5331 01:58:39,140 --> 01:58:40,930 result we see no for the quantity so go ahead and write an outer join to produce 5332 01:58:40,930 --> 01:58:40,940 ahead and write an outer join to produce 5333 01:58:40,940 --> 01:58:45,820 ahead and write an outer join to produce this result 5334 01:58:45,820 --> 01:58:45,830 5335 01:58:45,830 --> 01:58:48,740 all right first we select everything 5336 01:58:48,740 --> 01:58:48,750 all right first we select everything 5337 01:58:48,750 --> 01:58:52,670 all right first we select everything from the products table and then do a 5338 01:58:52,670 --> 01:58:52,680 from the products table and then do a 5339 01:58:52,680 --> 01:58:57,530 from the products table and then do a left join with the order items table our 5340 01:58:57,530 --> 01:58:57,540 left join with the order items table our 5341 01:58:57,540 --> 01:59:00,530 left join with the order items table our joint condition is P the Product ID 5342 01:59:00,530 --> 01:59:00,540 joint condition is P the Product ID 5343 01:59:00,540 --> 01:59:05,330 joint condition is P the Product ID equals o ID product ID so because we're 5344 01:59:05,330 --> 01:59:05,340 equals o ID product ID so because we're 5345 01:59:05,340 --> 01:59:07,580 equals o ID product ID so because we're using a left join we'll get all the 5346 01:59:07,580 --> 01:59:07,590 using a left join we'll get all the 5347 01:59:07,590 --> 01:59:09,710 using a left join we'll get all the products in the products table whether 5348 01:59:09,710 --> 01:59:09,720 products in the products table whether 5349 01:59:09,720 --> 01:59:12,020 products in the products table whether this condition is true or not if they 5350 01:59:12,020 --> 01:59:12,030 this condition is true or not if they 5351 01:59:12,030 --> 01:59:13,729 this condition is true or not if they have never been ordered we still see 5352 01:59:13,729 --> 01:59:13,739 have never been ordered we still see 5353 01:59:13,739 --> 01:59:16,700 have never been ordered we still see them in the result now let's pick a few 5354 01:59:16,700 --> 01:59:16,710 them in the result now let's pick a few 5355 01:59:16,710 --> 01:59:20,170 them in the result now let's pick a few columns for clarity so P dot product ID 5356 01:59:20,170 --> 01:59:20,180 columns for clarity so P dot product ID 5357 01:59:20,180 --> 01:59:26,150 columns for clarity so P dot product ID P name and oh I dot quantity that's it 5358 01:59:26,150 --> 01:59:26,160 P name and oh I dot quantity that's it 5359 01:59:26,160 --> 01:59:29,960 P name and oh I dot quantity that's it let's execute the query we get the same 5360 01:59:29,960 --> 01:59:29,970 let's execute the query we get the same 5361 01:59:29,970 --> 01:59:32,030 let's execute the query we get the same result as before so all the products are 5362 01:59:32,030 --> 01:59:32,040 result as before so all the products are 5363 01:59:32,040 --> 01:59:34,729 result as before so all the products are here and product number seven has never 5364 01:59:34,729 --> 01:59:34,739 here and product number seven has never 5365 01:59:34,739 --> 01:59:36,890 here and product number seven has never been ordered so we see null for the 5366 01:59:36,890 --> 01:59:36,900 been ordered so we see null for the 5367 01:59:36,900 --> 01:59:43,030 been ordered so we see null for the quantity 5368 01:59:43,030 --> 01:59:43,040 5369 01:59:43,040 --> 01:59:45,590 similar to inner joins we can use outer 5370 01:59:45,590 --> 01:59:45,600 similar to inner joins we can use outer 5371 01:59:45,600 --> 01:59:48,200 similar to inner joins we can use outer joins between multiple tables let me 5372 01:59:48,200 --> 01:59:48,210 joins between multiple tables let me 5373 01:59:48,210 --> 01:59:50,090 joins between multiple tables let me show you so here's the query that we 5374 01:59:50,090 --> 01:59:50,100 show you so here's the query that we 5375 01:59:50,100 --> 01:59:52,100 show you so here's the query that we wrote in the last tutorial you're doing 5376 01:59:52,100 --> 01:59:52,110 wrote in the last tutorial you're doing 5377 01:59:52,110 --> 01:59:55,040 wrote in the last tutorial you're doing a left join between customers and orders 5378 01:59:55,040 --> 01:59:55,050 a left join between customers and orders 5379 01:59:55,050 --> 01:59:59,060 a left join between customers and orders tables so when we execute this query we 5380 01:59:59,060 --> 01:59:59,070 tables so when we execute this query we 5381 01:59:59,070 --> 02:00:01,400 tables so when we execute this query we get all the customers whether they have 5382 02:00:01,400 --> 02:00:01,410 get all the customers whether they have 5383 02:00:01,410 --> 02:00:03,560 get all the customers whether they have an order or not if they have an order we 5384 02:00:03,560 --> 02:00:03,570 an order or not if they have an order we 5385 02:00:03,570 --> 02:00:07,250 an order or not if they have an order we see the order ID beautiful now if you 5386 02:00:07,250 --> 02:00:07,260 see the order ID beautiful now if you 5387 02:00:07,260 --> 02:00:09,890 see the order ID beautiful now if you look at the orders table you can see 5388 02:00:09,890 --> 02:00:09,900 look at the orders table you can see 5389 02:00:09,900 --> 02:00:12,200 look at the orders table you can see that some of our orders have a shipper 5390 02:00:12,200 --> 02:00:12,210 that some of our orders have a shipper 5391 02:00:12,210 --> 02:00:14,090 that some of our orders have a shipper ID these are the orders that have been 5392 02:00:14,090 --> 02:00:14,100 ID these are the orders that have been 5393 02:00:14,100 --> 02:00:16,400 ID these are the orders that have been shipped so now let's join the orders 5394 02:00:16,400 --> 02:00:16,410 shipped so now let's join the orders 5395 02:00:16,410 --> 02:00:18,620 shipped so now let's join the orders table with the shippers table to display 5396 02:00:18,620 --> 02:00:18,630 table with the shippers table to display 5397 02:00:18,630 --> 02:00:21,020 table with the shippers table to display the name of the shipper in the result so 5398 02:00:21,020 --> 02:00:21,030 the name of the shipper in the result so 5399 02:00:21,030 --> 02:00:24,370 the name of the shipper in the result so back to a query after this left join 5400 02:00:24,370 --> 02:00:24,380 back to a query after this left join 5401 02:00:24,380 --> 02:00:27,560 back to a query after this left join let's write another join here I'm doing 5402 02:00:27,560 --> 02:00:27,570 let's write another join here I'm doing 5403 02:00:27,570 --> 02:00:29,390 let's write another join here I'm doing an inner join so let's inner join 5404 02:00:29,390 --> 02:00:29,400 an inner join so let's inner join 5405 02:00:29,400 --> 02:00:31,280 an inner join so let's inner join the orders table with the shippers table 5406 02:00:31,280 --> 02:00:31,290 the orders table with the shippers table 5407 02:00:31,290 --> 02:00:36,440 the orders table with the shippers table join shippers we call it SH on what is 5408 02:00:36,440 --> 02:00:36,450 join shippers we call it SH on what is 5409 02:00:36,450 --> 02:00:40,010 join shippers we call it SH on what is the join condition well oh that shipper 5410 02:00:40,010 --> 02:00:40,020 the join condition well oh that shipper 5411 02:00:40,020 --> 02:00:44,980 the join condition well oh that shipper ID should be equal to SH that shipper ID 5412 02:00:44,980 --> 02:00:44,990 ID should be equal to SH that shipper ID 5413 02:00:44,990 --> 02:00:48,650 ID should be equal to SH that shipper ID alright so in this query we have a left 5414 02:00:48,650 --> 02:00:48,660 alright so in this query we have a left 5415 02:00:48,660 --> 02:00:52,130 alright so in this query we have a left outer join and an inner join let's see 5416 02:00:52,130 --> 02:00:52,140 outer join and an inner join let's see 5417 02:00:52,140 --> 02:00:54,310 outer join and an inner join let's see what we get 5418 02:00:54,310 --> 02:00:54,320 what we get 5419 02:00:54,320 --> 02:00:58,010 what we get alright we only see five records but we 5420 02:00:58,010 --> 02:00:58,020 alright we only see five records but we 5421 02:00:58,020 --> 02:00:59,900 alright we only see five records but we have more orders so here we have the 5422 02:00:59,900 --> 02:00:59,910 have more orders so here we have the 5423 02:00:59,910 --> 02:01:01,790 have more orders so here we have the same problem we had before several 5424 02:01:01,790 --> 02:01:01,800 same problem we had before several 5425 02:01:01,800 --> 02:01:04,130 same problem we had before several orders don't have a shipper and that is 5426 02:01:04,130 --> 02:01:04,140 orders don't have a shipper and that is 5427 02:01:04,140 --> 02:01:06,410 orders don't have a shipper and that is why they are not returned here in other 5428 02:01:06,410 --> 02:01:06,420 why they are not returned here in other 5429 02:01:06,420 --> 02:01:08,870 why they are not returned here in other words this join condition is not true 5430 02:01:08,870 --> 02:01:08,880 words this join condition is not true 5431 02:01:08,880 --> 02:01:11,450 words this join condition is not true for some other orders so back to the 5432 02:01:11,450 --> 02:01:11,460 for some other orders so back to the 5433 02:01:11,460 --> 02:01:14,450 for some other orders so back to the orders table as an example this first 5434 02:01:14,450 --> 02:01:14,460 orders table as an example this first 5435 02:01:14,460 --> 02:01:17,030 orders table as an example this first order doesn't have a shipper ship our ID 5436 02:01:17,030 --> 02:01:17,040 order doesn't have a shipper ship our ID 5437 02:01:17,040 --> 02:01:18,920 order doesn't have a shipper ship our ID is null and that is why it's not 5438 02:01:18,920 --> 02:01:18,930 is null and that is why it's not 5439 02:01:18,930 --> 02:01:21,650 is null and that is why it's not returned in the query result so to solve 5440 02:01:21,650 --> 02:01:21,660 returned in the query result so to solve 5441 02:01:21,660 --> 02:01:23,450 returned in the query result so to solve this problem we should use a left join 5442 02:01:23,450 --> 02:01:23,460 this problem we should use a left join 5443 02:01:23,460 --> 02:01:25,460 this problem we should use a left join you want to make sure that all orders 5444 02:01:25,460 --> 02:01:25,470 you want to make sure that all orders 5445 02:01:25,470 --> 02:01:27,440 you want to make sure that all orders are returned whether they have a shipper 5446 02:01:27,440 --> 02:01:27,450 are returned whether they have a shipper 5447 02:01:27,450 --> 02:01:31,100 are returned whether they have a shipper or not so back to the query we need to 5448 02:01:31,100 --> 02:01:31,110 or not so back to the query we need to 5449 02:01:31,110 --> 02:01:33,140 or not so back to the query we need to replace this inner join with the left 5450 02:01:33,140 --> 02:01:33,150 replace this inner join with the left 5451 02:01:33,150 --> 02:01:34,409 replace this inner join with the left join 5452 02:01:34,409 --> 02:01:34,419 join 5453 02:01:34,419 --> 02:01:36,179 join so let's execute the query and see what 5454 02:01:36,179 --> 02:01:36,189 so let's execute the query and see what 5455 02:01:36,189 --> 02:01:39,060 so let's execute the query and see what happens now we should have quite a few 5456 02:01:39,060 --> 02:01:39,070 happens now we should have quite a few 5457 02:01:39,070 --> 02:01:41,729 happens now we should have quite a few more orders there you go now to make 5458 02:01:41,729 --> 02:01:41,739 more orders there you go now to make 5459 02:01:41,739 --> 02:01:43,770 more orders there you go now to make this example more interesting I'm gonna 5460 02:01:43,770 --> 02:01:43,780 this example more interesting I'm gonna 5461 02:01:43,780 --> 02:01:48,029 this example more interesting I'm gonna add the shipper name here so back to our 5462 02:01:48,029 --> 02:01:48,039 add the shipper name here so back to our 5463 02:01:48,039 --> 02:01:51,060 add the shipper name here so back to our select clause let's add a new column so 5464 02:01:51,060 --> 02:01:51,070 select clause let's add a new column so 5465 02:01:51,070 --> 02:01:54,029 select clause let's add a new column so shipper dot name and we can give it an 5466 02:01:54,029 --> 02:01:54,039 shipper dot name and we can give it an 5467 02:01:54,039 --> 02:01:57,600 shipper dot name and we can give it an alias like shipper let's execute the 5468 02:01:57,600 --> 02:01:57,610 alias like shipper let's execute the 5469 02:01:57,610 --> 02:02:01,169 alias like shipper let's execute the query and here's the result so we get 5470 02:02:01,169 --> 02:02:01,179 query and here's the result so we get 5471 02:02:01,179 --> 02:02:03,239 query and here's the result so we get all the customers whether they have an 5472 02:02:03,239 --> 02:02:03,249 all the customers whether they have an 5473 02:02:03,249 --> 02:02:06,239 all the customers whether they have an order or not and for those who do have 5474 02:02:06,239 --> 02:02:06,249 order or not and for those who do have 5475 02:02:06,249 --> 02:02:08,879 order or not and for those who do have an order we get all the orders whether 5476 02:02:08,879 --> 02:02:08,889 an order we get all the orders whether 5477 02:02:08,889 --> 02:02:11,489 an order we get all the orders whether they have a shipper or not this is the 5478 02:02:11,489 --> 02:02:11,499 they have a shipper or not this is the 5479 02:02:11,499 --> 02:02:14,790 they have a shipper or not this is the power of outer joins now in the last 5480 02:02:14,790 --> 02:02:14,800 power of outer joins now in the last 5481 02:02:14,800 --> 02:02:16,080 power of outer joins now in the last tutorial you learned that you can get 5482 02:02:16,080 --> 02:02:16,090 tutorial you learned that you can get 5483 02:02:16,090 --> 02:02:18,569 tutorial you learned that you can get the same result with both a left join or 5484 02:02:18,569 --> 02:02:18,579 the same result with both a left join or 5485 02:02:18,579 --> 02:02:20,429 the same result with both a left join or a right joint you just have to swap the 5486 02:02:20,429 --> 02:02:20,439 a right joint you just have to swap the 5487 02:02:20,439 --> 02:02:23,279 a right joint you just have to swap the order of the tables however as a best 5488 02:02:23,279 --> 02:02:23,289 order of the tables however as a best 5489 02:02:23,289 --> 02:02:23,879 order of the tables however as a best practice 5490 02:02:23,879 --> 02:02:23,889 practice 5491 02:02:23,889 --> 02:02:26,250 practice avoid using right joints because when 5492 02:02:26,250 --> 02:02:26,260 avoid using right joints because when 5493 02:02:26,260 --> 02:02:27,839 avoid using right joints because when you're joining multiple tables and you 5494 02:02:27,839 --> 02:02:27,849 you're joining multiple tables and you 5495 02:02:27,849 --> 02:02:29,459 you're joining multiple tables and you have left and right and inner join 5496 02:02:29,459 --> 02:02:29,469 have left and right and inner join 5497 02:02:29,469 --> 02:02:32,279 have left and right and inner join things get really complex someone else 5498 02:02:32,279 --> 02:02:32,289 things get really complex someone else 5499 02:02:32,289 --> 02:02:33,989 things get really complex someone else reading your code will have difficulty 5500 02:02:33,989 --> 02:02:33,999 reading your code will have difficulty 5501 02:02:33,999 --> 02:02:35,609 reading your code will have difficulty visualizing how you're joining these 5502 02:02:35,609 --> 02:02:35,619 visualizing how you're joining these 5503 02:02:35,619 --> 02:02:38,129 visualizing how you're joining these tables as an example if you had a right 5504 02:02:38,129 --> 02:02:38,139 tables as an example if you had a right 5505 02:02:38,139 --> 02:02:40,770 tables as an example if you had a right joint here and then a left joint after 5506 02:02:40,770 --> 02:02:40,780 joint here and then a left joint after 5507 02:02:40,780 --> 02:02:42,719 joint here and then a left joint after it would be harder to visualize how 5508 02:02:42,719 --> 02:02:42,729 it would be harder to visualize how 5509 02:02:42,729 --> 02:02:45,089 it would be harder to visualize how these tables are getting joined so as a 5510 02:02:45,089 --> 02:02:45,099 these tables are getting joined so as a 5511 02:02:45,099 --> 02:02:47,580 these tables are getting joined so as a best practice avoid right joints and use 5512 02:02:47,580 --> 02:02:47,590 best practice avoid right joints and use 5513 02:02:47,590 --> 02:02:52,720 best practice avoid right joints and use left joins instead 5514 02:02:52,720 --> 02:02:52,730 5515 02:02:52,730 --> 02:02:55,510 and here's your exercise for this 5516 02:02:55,510 --> 02:02:55,520 and here's your exercise for this 5517 02:02:55,520 --> 02:02:57,520 and here's your exercise for this tutorial I want you to write a query 5518 02:02:57,520 --> 02:02:57,530 tutorial I want you to write a query 5519 02:02:57,530 --> 02:02:59,680 tutorial I want you to write a query that produces this result so here we 5520 02:02:59,680 --> 02:02:59,690 that produces this result so here we 5521 02:02:59,690 --> 02:03:02,380 that produces this result so here we have these columns order date order ID 5522 02:03:02,380 --> 02:03:02,390 have these columns order date order ID 5523 02:03:02,390 --> 02:03:05,350 have these columns order date order ID the first name of the customer the 5524 02:03:05,350 --> 02:03:05,360 the first name of the customer the 5525 02:03:05,360 --> 02:03:07,090 the first name of the customer the shaper and you can see that some of our 5526 02:03:07,090 --> 02:03:07,100 shaper and you can see that some of our 5527 02:03:07,100 --> 02:03:09,040 shaper and you can see that some of our orders are not shipped yet so here we 5528 02:03:09,040 --> 02:03:09,050 orders are not shipped yet so here we 5529 02:03:09,050 --> 02:03:12,669 orders are not shipped yet so here we have no and finally this status so go 5530 02:03:12,669 --> 02:03:12,679 have no and finally this status so go 5531 02:03:12,679 --> 02:03:14,350 have no and finally this status so go ahead and spend 2 to 3 minutes on this 5532 02:03:14,350 --> 02:03:14,360 ahead and spend 2 to 3 minutes on this 5533 02:03:14,360 --> 02:03:15,939 ahead and spend 2 to 3 minutes on this exercise when you're done come back 5534 02:03:15,939 --> 02:03:15,949 exercise when you're done come back 5535 02:03:15,949 --> 02:03:21,260 exercise when you're done come back continue watching 5536 02:03:21,260 --> 02:03:21,270 5537 02:03:21,270 --> 02:03:24,870 alright let's select everything from the 5538 02:03:24,870 --> 02:03:24,880 alright let's select everything from the 5539 02:03:24,880 --> 02:03:27,630 alright let's select everything from the orders table now we should join this 5540 02:03:27,630 --> 02:03:27,640 orders table now we should join this 5541 02:03:27,640 --> 02:03:32,040 orders table now we should join this with customers on oh that customer ID 5542 02:03:32,040 --> 02:03:32,050 with customers on oh that customer ID 5543 02:03:32,050 --> 02:03:35,060 with customers on oh that customer ID should be equal to see that customer ID 5544 02:03:35,060 --> 02:03:35,070 should be equal to see that customer ID 5545 02:03:35,070 --> 02:03:37,470 should be equal to see that customer ID here I'm using an inner join because 5546 02:03:37,470 --> 02:03:37,480 here I'm using an inner join because 5547 02:03:37,480 --> 02:03:40,860 here I'm using an inner join because every order does have a customer so this 5548 02:03:40,860 --> 02:03:40,870 every order does have a customer so this 5549 02:03:40,870 --> 02:03:42,900 every order does have a customer so this condition is always valid it doesn't 5550 02:03:42,900 --> 02:03:42,910 condition is always valid it doesn't 5551 02:03:42,910 --> 02:03:44,760 condition is always valid it doesn't matter if we use a left join or an inner 5552 02:03:44,760 --> 02:03:44,770 matter if we use a left join or an inner 5553 02:03:44,770 --> 02:03:47,430 matter if we use a left join or an inner join here okay now if we're going any 5554 02:03:47,430 --> 02:03:47,440 join here okay now if we're going any 5555 02:03:47,440 --> 02:03:49,710 join here okay now if we're going any further let's pick our columns so from 5556 02:03:49,710 --> 02:03:49,720 further let's pick our columns so from 5557 02:03:49,720 --> 02:03:52,670 further let's pick our columns so from the orders table I want to pick order ID 5558 02:03:52,670 --> 02:03:52,680 the orders table I want to pick order ID 5559 02:03:52,680 --> 02:03:56,970 the orders table I want to pick order ID followed by order date and then customer 5560 02:03:56,970 --> 02:03:56,980 followed by order date and then customer 5561 02:03:56,980 --> 02:04:01,080 followed by order date and then customer dot first-name which we can optionally 5562 02:04:01,080 --> 02:04:01,090 dot first-name which we can optionally 5563 02:04:01,090 --> 02:04:05,820 dot first-name which we can optionally rename to customer alright next we need 5564 02:04:05,820 --> 02:04:05,830 rename to customer alright next we need 5565 02:04:05,830 --> 02:04:09,120 rename to customer alright next we need to select the shipper so we join the 5566 02:04:09,120 --> 02:04:09,130 to select the shipper so we join the 5567 02:04:09,130 --> 02:04:13,230 to select the shipper so we join the result with the shippers table on order 5568 02:04:13,230 --> 02:04:13,240 result with the shippers table on order 5569 02:04:13,240 --> 02:04:16,710 result with the shippers table on order that shipper ID equal to shipper that 5570 02:04:16,710 --> 02:04:16,720 that shipper ID equal to shipper that 5571 02:04:16,720 --> 02:04:20,220 that shipper ID equal to shipper that shipper ID however if you use an inner 5572 02:04:20,220 --> 02:04:20,230 shipper ID however if you use an inner 5573 02:04:20,230 --> 02:04:22,260 shipper ID however if you use an inner join here because some of our orders 5574 02:04:22,260 --> 02:04:22,270 join here because some of our orders 5575 02:04:22,270 --> 02:04:25,140 join here because some of our orders don't have a shipper we're only going to 5576 02:04:25,140 --> 02:04:25,150 don't have a shipper we're only going to 5577 02:04:25,150 --> 02:04:26,430 don't have a shipper we're only going to see the orders that have been shipped 5578 02:04:26,430 --> 02:04:26,440 see the orders that have been shipped 5579 02:04:26,440 --> 02:04:29,850 see the orders that have been shipped let me show you so for clarity I'm gonna 5580 02:04:29,850 --> 02:04:29,860 let me show you so for clarity I'm gonna 5581 02:04:29,860 --> 02:04:32,160 let me show you so for clarity I'm gonna add the shippers name here so shipper 5582 02:04:32,160 --> 02:04:32,170 add the shippers name here so shipper 5583 02:04:32,170 --> 02:04:35,520 add the shippers name here so shipper and that name as shipper let's execute 5584 02:04:35,520 --> 02:04:35,530 and that name as shipper let's execute 5585 02:04:35,530 --> 02:04:38,880 and that name as shipper let's execute the query there you go we only see the 5586 02:04:38,880 --> 02:04:38,890 the query there you go we only see the 5587 02:04:38,890 --> 02:04:41,220 the query there you go we only see the orders that have been shipped but you 5588 02:04:41,220 --> 02:04:41,230 orders that have been shipped but you 5589 02:04:41,230 --> 02:04:44,190 orders that have been shipped but you want to see all the orders right so we 5590 02:04:44,190 --> 02:04:44,200 want to see all the orders right so we 5591 02:04:44,200 --> 02:04:47,310 want to see all the orders right so we need to change the second join to a left 5592 02:04:47,310 --> 02:04:47,320 need to change the second join to a left 5593 02:04:47,320 --> 02:04:50,580 need to change the second join to a left join so all orders are returned whether 5594 02:04:50,580 --> 02:04:50,590 join so all orders are returned whether 5595 02:04:50,590 --> 02:04:53,490 join so all orders are returned whether they have a shipper or not let's execute 5596 02:04:53,490 --> 02:04:53,500 they have a shipper or not let's execute 5597 02:04:53,500 --> 02:04:57,990 they have a shipper or not let's execute the query one more time there you go now 5598 02:04:57,990 --> 02:04:58,000 the query one more time there you go now 5599 02:04:58,000 --> 02:04:59,820 the query one more time there you go now we see all the orders from number one to 5600 02:04:59,820 --> 02:04:59,830 we see all the orders from number one to 5601 02:04:59,830 --> 02:05:02,910 we see all the orders from number one to number ten beautiful finally way to add 5602 02:05:02,910 --> 02:05:02,920 number ten beautiful finally way to add 5603 02:05:02,920 --> 02:05:06,000 number ten beautiful finally way to add the status column here so we need to do 5604 02:05:06,000 --> 02:05:06,010 the status column here so we need to do 5605 02:05:06,010 --> 02:05:09,810 the status column here so we need to do another join here join with order 5606 02:05:09,810 --> 02:05:09,820 another join here join with order 5607 02:05:09,820 --> 02:05:13,430 another join here join with order statuses which we abbreviate as OS on 5608 02:05:13,430 --> 02:05:13,440 statuses which we abbreviate as OS on 5609 02:05:13,440 --> 02:05:18,690 statuses which we abbreviate as OS on all that status equal to AU s dot order 5610 02:05:18,690 --> 02:05:18,700 all that status equal to AU s dot order 5611 02:05:18,700 --> 02:05:21,450 all that status equal to AU s dot order status ID you can see that I have 5612 02:05:21,450 --> 02:05:21,460 status ID you can see that I have 5613 02:05:21,460 --> 02:05:22,920 status ID you can see that I have designed this database such that 5614 02:05:22,920 --> 02:05:22,930 designed this database such that 5615 02:05:22,930 --> 02:05:25,230 designed this database such that sometimes our column names are exactly 5616 02:05:25,230 --> 02:05:25,240 sometimes our column names are exactly 5617 02:05:25,240 --> 02:05:28,200 sometimes our column names are exactly identical but in other cases they don't 5618 02:05:28,200 --> 02:05:28,210 identical but in other cases they don't 5619 02:05:28,210 --> 02:05:30,510 identical but in other cases they don't match so in the order table we call this 5620 02:05:30,510 --> 02:05:30,520 match so in the order table we call this 5621 02:05:30,520 --> 02:05:33,969 match so in the order table we call this column status as opposed to order status 5622 02:05:33,969 --> 02:05:33,979 column status as opposed to order status 5623 02:05:33,979 --> 02:05:36,189 column status as opposed to order status I D and this is deliberate because a lot 5624 02:05:36,189 --> 02:05:36,199 I D and this is deliberate because a lot 5625 02:05:36,199 --> 02:05:38,529 I D and this is deliberate because a lot of real databases are like that all 5626 02:05:38,529 --> 02:05:38,539 of real databases are like that all 5627 02:05:38,539 --> 02:05:41,589 of real databases are like that all right now let's add the status name here 5628 02:05:41,589 --> 02:05:41,599 right now let's add the status name here 5629 02:05:41,599 --> 02:05:46,109 right now let's add the status name here so order status the name as status 5630 02:05:46,109 --> 02:05:46,119 so order status the name as status 5631 02:05:46,119 --> 02:05:51,520 so order status the name as status execute the query and we can see all the 5632 02:05:51,520 --> 02:05:51,530 execute the query and we can see all the 5633 02:05:51,530 --> 02:05:53,109 execute the query and we can see all the orders here for each order we have to 5634 02:05:53,109 --> 02:05:53,119 orders here for each order we have to 5635 02:05:53,119 --> 02:05:55,779 orders here for each order we have to date the customer the shipper and the 5636 02:05:55,779 --> 02:05:55,789 date the customer the shipper and the 5637 02:05:55,789 --> 02:06:01,920 date the customer the shipper and the status 5638 02:06:01,920 --> 02:06:01,930 5639 02:06:01,930 --> 02:06:04,120 earlier we're talking about self joins 5640 02:06:04,120 --> 02:06:04,130 earlier we're talking about self joins 5641 02:06:04,130 --> 02:06:06,850 earlier we're talking about self joins in sequa so hearing the sequel HR 5642 02:06:06,850 --> 02:06:06,860 in sequa so hearing the sequel HR 5643 02:06:06,860 --> 02:06:10,319 in sequa so hearing the sequel HR database we have this employees table 5644 02:06:10,319 --> 02:06:10,329 database we have this employees table 5645 02:06:10,329 --> 02:06:12,930 database we have this employees table we wrote a query to get all the 5646 02:06:12,930 --> 02:06:12,940 we wrote a query to get all the 5647 02:06:12,940 --> 02:06:15,330 we wrote a query to get all the employees and their manager so here we 5648 02:06:15,330 --> 02:06:15,340 employees and their manager so here we 5649 02:06:15,340 --> 02:06:17,129 employees and their manager so here we have this column reports - that 5650 02:06:17,129 --> 02:06:17,139 have this column reports - that 5651 02:06:17,139 --> 02:06:19,040 have this column reports - that specifies the manager for each employee 5652 02:06:19,040 --> 02:06:19,050 specifies the manager for each employee 5653 02:06:19,050 --> 02:06:21,540 specifies the manager for each employee so let's go back and rewrite this query 5654 02:06:21,540 --> 02:06:21,550 so let's go back and rewrite this query 5655 02:06:21,550 --> 02:06:23,129 so let's go back and rewrite this query to get all the employees and their 5656 02:06:23,129 --> 02:06:23,139 to get all the employees and their 5657 02:06:23,139 --> 02:06:25,819 to get all the employees and their manager back to our query editor window 5658 02:06:25,819 --> 02:06:25,829 manager back to our query editor window 5659 02:06:25,829 --> 02:06:29,870 manager back to our query editor window first let's use a sequel HR database 5660 02:06:29,870 --> 02:06:29,880 first let's use a sequel HR database 5661 02:06:29,880 --> 02:06:33,629 first let's use a sequel HR database then select everything from the 5662 02:06:33,629 --> 02:06:33,639 then select everything from the 5663 02:06:33,639 --> 02:06:35,709 then select everything from the employee's table 5664 02:06:35,709 --> 02:06:35,719 employee's table 5665 02:06:35,719 --> 02:06:38,379 employee's table we give it an alias and then join it 5666 02:06:38,379 --> 02:06:38,389 we give it an alias and then join it 5667 02:06:38,389 --> 02:06:41,350 we give it an alias and then join it with itself so this is what we call a 5668 02:06:41,350 --> 02:06:41,360 with itself so this is what we call a 5669 02:06:41,360 --> 02:06:43,659 with itself so this is what we call a self join now we're gonna use a 5670 02:06:43,659 --> 02:06:43,669 self join now we're gonna use a 5671 02:06:43,669 --> 02:06:47,399 self join now we're gonna use a different alias like M for managers now 5672 02:06:47,399 --> 02:06:47,409 different alias like M for managers now 5673 02:06:47,409 --> 02:06:50,439 different alias like M for managers now what is the joint condition a dot 5674 02:06:50,439 --> 02:06:50,449 what is the joint condition a dot 5675 02:06:50,449 --> 02:06:53,529 what is the joint condition a dot reports to should be equal to m dot 5676 02:06:53,529 --> 02:06:53,539 reports to should be equal to m dot 5677 02:06:53,539 --> 02:06:57,640 reports to should be equal to m dot employee ID right now for clarity let's 5678 02:06:57,640 --> 02:06:57,650 employee ID right now for clarity let's 5679 02:06:57,650 --> 02:06:59,919 employee ID right now for clarity let's pick only three columns so either the 5680 02:06:59,919 --> 02:06:59,929 pick only three columns so either the 5681 02:06:59,929 --> 02:07:05,290 pick only three columns so either the employee ID e dot first-name and m dot 5682 02:07:05,290 --> 02:07:05,300 employee ID e dot first-name and m dot 5683 02:07:05,300 --> 02:07:08,919 employee ID e dot first-name and m dot first-name which were renamed to manager 5684 02:07:08,919 --> 02:07:08,929 first-name which were renamed to manager 5685 02:07:08,929 --> 02:07:11,709 first-name which were renamed to manager alright let's execute this query and see 5686 02:07:11,709 --> 02:07:11,719 alright let's execute this query and see 5687 02:07:11,719 --> 02:07:16,899 alright let's execute this query and see what we get so here's the result as we 5688 02:07:16,899 --> 02:07:16,909 what we get so here's the result as we 5689 02:07:16,909 --> 02:07:18,489 what we get so here's the result as we can see all these employees have the 5690 02:07:18,489 --> 02:07:18,499 can see all these employees have the 5691 02:07:18,499 --> 02:07:21,370 can see all these employees have the same manager however there is something 5692 02:07:21,370 --> 02:07:21,380 same manager however there is something 5693 02:07:21,380 --> 02:07:23,589 same manager however there is something missing here we don't have a record for 5694 02:07:23,589 --> 02:07:23,599 missing here we don't have a record for 5695 02:07:23,599 --> 02:07:26,319 missing here we don't have a record for this person this manager himself so what 5696 02:07:26,319 --> 02:07:26,329 this person this manager himself so what 5697 02:07:26,329 --> 02:07:28,629 this person this manager himself so what is missing is a record where we can see 5698 02:07:28,629 --> 02:07:28,639 is missing is a record where we can see 5699 02:07:28,639 --> 02:07:31,390 is missing is a record where we can see the employee ID for this person their 5700 02:07:31,390 --> 02:07:31,400 the employee ID for this person their 5701 02:07:31,400 --> 02:07:33,399 the employee ID for this person their name and their manager which should be 5702 02:07:33,399 --> 02:07:33,409 name and their manager which should be 5703 02:07:33,409 --> 02:07:35,890 name and their manager which should be no because this person is the CEO or the 5704 02:07:35,890 --> 02:07:35,900 no because this person is the CEO or the 5705 02:07:35,900 --> 02:07:37,899 no because this person is the CEO or the head of the company but why is this 5706 02:07:37,899 --> 02:07:37,909 head of the company but why is this 5707 02:07:37,909 --> 02:07:41,699 head of the company but why is this happening the reason is our inner joy 5708 02:07:41,699 --> 02:07:41,709 happening the reason is our inner joy 5709 02:07:41,709 --> 02:07:44,259 happening the reason is our inner joy because this condition we have here will 5710 02:07:44,259 --> 02:07:44,269 because this condition we have here will 5711 02:07:44,269 --> 02:07:46,929 because this condition we have here will only return people who have a manager we 5712 02:07:46,929 --> 02:07:46,939 only return people who have a manager we 5713 02:07:46,939 --> 02:07:48,489 only return people who have a manager we can solve this problem by using a left 5714 02:07:48,489 --> 02:07:48,499 can solve this problem by using a left 5715 02:07:48,499 --> 02:07:51,339 can solve this problem by using a left join so we do a left join because we 5716 02:07:51,339 --> 02:07:51,349 join so we do a left join because we 5717 02:07:51,349 --> 02:07:53,439 join so we do a left join because we want to get every employee in this table 5718 02:07:53,439 --> 02:07:53,449 want to get every employee in this table 5719 02:07:53,449 --> 02:07:56,429 want to get every employee in this table whether they have a manager or not 5720 02:07:56,429 --> 02:07:56,439 whether they have a manager or not 5721 02:07:56,439 --> 02:07:59,319 whether they have a manager or not ok now let's execute the query one more 5722 02:07:59,319 --> 02:07:59,329 ok now let's execute the query one more 5723 02:07:59,329 --> 02:08:03,069 ok now let's execute the query one more time there you go now we have a record 5724 02:08:03,069 --> 02:08:03,079 time there you go now we have a record 5725 02:08:03,079 --> 02:08:05,439 time there you go now we have a record for this person the manager as you can 5726 02:08:05,439 --> 02:08:05,449 for this person the manager as you can 5727 02:08:05,449 --> 02:08:07,719 for this person the manager as you can see this person does not have a manager 5728 02:08:07,719 --> 02:08:07,729 see this person does not have a manager 5729 02:08:07,729 --> 02:08:15,549 see this person does not have a manager that's why we have null here back to a 5730 02:08:15,549 --> 02:08:15,559 that's why we have null here back to a 5731 02:08:15,559 --> 02:08:17,560 that's why we have null here back to a sequel store database here we have a 5732 02:08:17,560 --> 02:08:17,570 sequel store database here we have a 5733 02:08:17,570 --> 02:08:19,810 sequel store database here we have a simple query that joins the orders table 5734 02:08:19,810 --> 02:08:19,820 simple query that joins the orders table 5735 02:08:19,820 --> 02:08:22,419 simple query that joins the orders table with the customers table and here's our 5736 02:08:22,419 --> 02:08:22,429 with the customers table and here's our 5737 02:08:22,429 --> 02:08:24,189 with the customers table and here's our joint condition you have seen several 5738 02:08:24,189 --> 02:08:24,199 joint condition you have seen several 5739 02:08:24,199 --> 02:08:26,379 joint condition you have seen several examples of this before now as our 5740 02:08:26,379 --> 02:08:26,389 examples of this before now as our 5741 02:08:26,389 --> 02:08:28,750 examples of this before now as our queries get more complex these joint 5742 02:08:28,750 --> 02:08:28,760 queries get more complex these joint 5743 02:08:28,760 --> 02:08:30,640 queries get more complex these joint conditions get in the way they make our 5744 02:08:30,640 --> 02:08:30,650 conditions get in the way they make our 5745 02:08:30,650 --> 02:08:32,529 conditions get in the way they make our queries hard to read but the good news 5746 02:08:32,529 --> 02:08:32,539 queries hard to read but the good news 5747 02:08:32,539 --> 02:08:34,779 queries hard to read but the good news is that in MySQL we have a powerful 5748 02:08:34,779 --> 02:08:34,789 is that in MySQL we have a powerful 5749 02:08:34,789 --> 02:08:37,540 is that in MySQL we have a powerful feature for simplifying his queries if 5750 02:08:37,540 --> 02:08:37,550 feature for simplifying his queries if 5751 02:08:37,550 --> 02:08:40,000 feature for simplifying his queries if the column name is exactly the same 5752 02:08:40,000 --> 02:08:40,010 the column name is exactly the same 5753 02:08:40,010 --> 02:08:43,149 the column name is exactly the same across these two tables we can replace 5754 02:08:43,149 --> 02:08:43,159 across these two tables we can replace 5755 02:08:43,159 --> 02:08:45,429 across these two tables we can replace the on clause with a using clause which 5756 02:08:45,429 --> 02:08:45,439 the on clause with a using clause which 5757 02:08:45,439 --> 02:08:47,649 the on clause with a using clause which is simpler and shorter let me show you 5758 02:08:47,649 --> 02:08:47,659 is simpler and shorter let me show you 5759 02:08:47,659 --> 02:08:49,679 is simpler and shorter let me show you so I'm going to comment out this line 5760 02:08:49,679 --> 02:08:49,689 so I'm going to comment out this line 5761 02:08:49,689 --> 02:08:53,310 so I'm going to comment out this line and instead type out using in 5762 02:08:53,310 --> 02:08:53,320 and instead type out using in 5763 02:08:53,320 --> 02:08:55,469 and instead type out using in parentheses we type out the column name 5764 02:08:55,469 --> 02:08:55,479 parentheses we type out the column name 5765 02:08:55,479 --> 02:08:58,439 parentheses we type out the column name that is customer ID what we have on line 5766 02:08:58,439 --> 02:08:58,449 that is customer ID what we have on line 5767 02:08:58,449 --> 02:09:00,419 that is customer ID what we have on line seven is exactly identical to what we 5768 02:09:00,419 --> 02:09:00,429 seven is exactly identical to what we 5769 02:09:00,429 --> 02:09:02,759 seven is exactly identical to what we have on line six but is shorter and 5770 02:09:02,759 --> 02:09:02,769 have on line six but is shorter and 5771 02:09:02,769 --> 02:09:05,669 have on line six but is shorter and easier to read so let me delete this 5772 02:09:05,669 --> 02:09:05,679 easier to read so let me delete this 5773 02:09:05,679 --> 02:09:08,520 easier to read so let me delete this line we can add another joint statement 5774 02:09:08,520 --> 02:09:08,530 line we can add another joint statement 5775 02:09:08,530 --> 02:09:10,379 line we can add another joint statement here to join the orders for the shippers 5776 02:09:10,379 --> 02:09:10,389 here to join the orders for the shippers 5777 02:09:10,389 --> 02:09:14,200 here to join the orders for the shippers so join with shippers 5778 02:09:14,200 --> 02:09:14,210 so join with shippers 5779 02:09:14,210 --> 02:09:18,920 so join with shippers using shipper ID in both these tables we 5780 02:09:18,920 --> 02:09:18,930 using shipper ID in both these tables we 5781 02:09:18,930 --> 02:09:20,950 using shipper ID in both these tables we have a column with the exact same name 5782 02:09:20,950 --> 02:09:20,960 have a column with the exact same name 5783 02:09:20,960 --> 02:09:23,830 have a column with the exact same name alright now let's execute this query 5784 02:09:23,830 --> 02:09:23,840 alright now let's execute this query 5785 02:09:23,840 --> 02:09:27,350 alright now let's execute this query this is what we get we have the order ID 5786 02:09:27,350 --> 02:09:27,360 this is what we get we have the order ID 5787 02:09:27,360 --> 02:09:29,090 this is what we get we have the order ID followed by the first name of the 5788 02:09:29,090 --> 02:09:29,100 followed by the first name of the 5789 02:09:29,100 --> 02:09:32,920 followed by the first name of the customer let's add a new column here so 5790 02:09:32,920 --> 02:09:32,930 customer let's add a new column here so 5791 02:09:32,930 --> 02:09:38,000 customer let's add a new column here so I'm gonna add SH that name that is the 5792 02:09:38,000 --> 02:09:38,010 I'm gonna add SH that name that is the 5793 02:09:38,010 --> 02:09:40,640 I'm gonna add SH that name that is the name of the shipper so our shipper now 5794 02:09:40,640 --> 02:09:40,650 name of the shipper so our shipper now 5795 02:09:40,650 --> 02:09:42,110 name of the shipper so our shipper now obviously because some of our orders are 5796 02:09:42,110 --> 02:09:42,120 obviously because some of our orders are 5797 02:09:42,120 --> 02:09:43,910 obviously because some of our orders are not shipped we need to replace this 5798 02:09:43,910 --> 02:09:43,920 not shipped we need to replace this 5799 02:09:43,920 --> 02:09:48,530 not shipped we need to replace this inner join with a left join so we can 5800 02:09:48,530 --> 02:09:48,540 inner join with a left join so we can 5801 02:09:48,540 --> 02:09:50,600 inner join with a left join so we can use the using keyboard with both inner 5802 02:09:50,600 --> 02:09:50,610 use the using keyboard with both inner 5803 02:09:50,610 --> 02:09:53,090 use the using keyboard with both inner and outer joins let's execute the query 5804 02:09:53,090 --> 02:09:53,100 and outer joins let's execute the query 5805 02:09:53,100 --> 02:09:56,960 and outer joins let's execute the query one more time there you go now we have 5806 02:09:56,960 --> 02:09:56,970 one more time there you go now we have 5807 02:09:56,970 --> 02:09:58,610 one more time there you go now we have the name of the shipper next to each 5808 02:09:58,610 --> 02:09:58,620 the name of the shipper next to each 5809 02:09:58,620 --> 02:10:02,000 the name of the shipper next to each order beautiful however we cannot use 5810 02:10:02,000 --> 02:10:02,010 order beautiful however we cannot use 5811 02:10:02,010 --> 02:10:04,370 order beautiful however we cannot use this technique to join the result with 5812 02:10:04,370 --> 02:10:04,380 this technique to join the result with 5813 02:10:04,380 --> 02:10:06,860 this technique to join the result with the order statuses table because in the 5814 02:10:06,860 --> 02:10:06,870 the order statuses table because in the 5815 02:10:06,870 --> 02:10:08,600 the order statuses table because in the orders table we have this column called 5816 02:10:08,600 --> 02:10:08,610 orders table we have this column called 5817 02:10:08,610 --> 02:10:11,720 orders table we have this column called status but in order statuses table this 5818 02:10:11,720 --> 02:10:11,730 status but in order statuses table this 5819 02:10:11,730 --> 02:10:13,880 status but in order statuses table this column has a different name its order 5820 02:10:13,880 --> 02:10:13,890 column has a different name its order 5821 02:10:13,890 --> 02:10:16,790 column has a different name its order status ID let me show you so order 5822 02:10:16,790 --> 02:10:16,800 status ID let me show you so order 5823 02:10:16,800 --> 02:10:19,580 status ID let me show you so order statuses columns there you go order 5824 02:10:19,580 --> 02:10:19,590 statuses columns there you go order 5825 02:10:19,590 --> 02:10:22,400 statuses columns there you go order status ID so the using keyword only 5826 02:10:22,400 --> 02:10:22,410 status ID so the using keyword only 5827 02:10:22,410 --> 02:10:24,920 status ID so the using keyword only works if the column name is exactly the 5828 02:10:24,920 --> 02:10:24,930 works if the column name is exactly the 5829 02:10:24,930 --> 02:10:27,590 works if the column name is exactly the same across different tables now what if 5830 02:10:27,590 --> 02:10:27,600 same across different tables now what if 5831 02:10:27,600 --> 02:10:29,540 same across different tables now what if we have multiple columns in our joint 5832 02:10:29,540 --> 02:10:29,550 we have multiple columns in our joint 5833 02:10:29,550 --> 02:10:31,850 we have multiple columns in our joint condition for example earlier we talked 5834 02:10:31,850 --> 02:10:31,860 condition for example earlier we talked 5835 02:10:31,860 --> 02:10:35,300 condition for example earlier we talked about this order items table I told you 5836 02:10:35,300 --> 02:10:35,310 about this order items table I told you 5837 02:10:35,310 --> 02:10:36,979 about this order items table I told you that in this table we have a composite 5838 02:10:36,979 --> 02:10:36,989 that in this table we have a composite 5839 02:10:36,989 --> 02:10:39,140 that in this table we have a composite primary key which basically means a 5840 02:10:39,140 --> 02:10:39,150 primary key which basically means a 5841 02:10:39,150 --> 02:10:41,090 primary key which basically means a primary key that consists of multiple 5842 02:10:41,090 --> 02:10:41,100 primary key that consists of multiple 5843 02:10:41,100 --> 02:10:43,520 primary key that consists of multiple columns so the combination of these two 5844 02:10:43,520 --> 02:10:43,530 columns so the combination of these two 5845 02:10:43,530 --> 02:10:45,920 columns so the combination of these two columns if uniquely identify each record 5846 02:10:45,920 --> 02:10:45,930 columns if uniquely identify each record 5847 02:10:45,930 --> 02:10:48,200 columns if uniquely identify each record in this table now if you want to join 5848 02:10:48,200 --> 02:10:48,210 in this table now if you want to join 5849 02:10:48,210 --> 02:10:51,500 in this table now if you want to join this table with order item note table in 5850 02:10:51,500 --> 02:10:51,510 this table with order item note table in 5851 02:10:51,510 --> 02:10:53,780 this table with order item note table in our joint condition we should compare 5852 02:10:53,780 --> 02:10:53,790 our joint condition we should compare 5853 02:10:53,790 --> 02:10:55,790 our joint condition we should compare both these columns with their 5854 02:10:55,790 --> 02:10:55,800 both these columns with their 5855 02:10:55,800 --> 02:10:58,430 both these columns with their corresponding columns in the order item 5856 02:10:58,430 --> 02:10:58,440 corresponding columns in the order item 5857 02:10:58,440 --> 02:11:00,770 corresponding columns in the order item note table so let's quickly write that 5858 02:11:00,770 --> 02:11:00,780 note table so let's quickly write that 5859 02:11:00,780 --> 02:11:02,780 note table so let's quickly write that query and it's simplified with the using 5860 02:11:02,780 --> 02:11:02,790 query and it's simplified with the using 5861 02:11:02,790 --> 02:11:08,390 query and it's simplified with the using keyword so select everything from order 5862 02:11:08,390 --> 02:11:08,400 keyword so select everything from order 5863 02:11:08,400 --> 02:11:14,920 keyword so select everything from order items now join it with order item notes 5864 02:11:14,920 --> 02:11:14,930 items now join it with order item notes 5865 02:11:14,930 --> 02:11:19,160 items now join it with order item notes on so here we need to compare oh I dot 5866 02:11:19,160 --> 02:11:19,170 on so here we need to compare oh I dot 5867 02:11:19,170 --> 02:11:22,790 on so here we need to compare oh I dot order ID with who I end that order ID 5868 02:11:22,790 --> 02:11:22,800 order ID with who I end that order ID 5869 02:11:22,800 --> 02:11:29,540 order ID with who I end that order ID and oh I dot product ID equal to or I n 5870 02:11:29,540 --> 02:11:29,550 and oh I dot product ID equal to or I n 5871 02:11:29,550 --> 02:11:33,050 and oh I dot product ID equal to or I n dot product ID this joint condition is 5872 02:11:33,050 --> 02:11:33,060 dot product ID this joint condition is 5873 02:11:33,060 --> 02:11:34,610 dot product ID this joint condition is kind of messy it's hard to read this 5874 02:11:34,610 --> 02:11:34,620 kind of messy it's hard to read this 5875 02:11:34,620 --> 02:11:36,800 kind of messy it's hard to read this query now we can simplify this query 5876 02:11:36,800 --> 02:11:36,810 query now we can simplify this query 5877 02:11:36,810 --> 02:11:38,990 query now we can simplify this query with the using keyword so we try it out 5878 02:11:38,990 --> 02:11:39,000 with the using keyword so we try it out 5879 02:11:39,000 --> 02:11:42,560 with the using keyword so we try it out using in parentheses we add both columns 5880 02:11:42,560 --> 02:11:42,570 using in parentheses we add both columns 5881 02:11:42,570 --> 02:11:45,380 using in parentheses we add both columns and separate them using a comma so order 5882 02:11:45,380 --> 02:11:45,390 and separate them using a comma so order 5883 02:11:45,390 --> 02:11:54,120 and separate them using a comma so order ID and Product ID isn't that better 5884 02:11:54,120 --> 02:11:54,130 5885 02:11:54,130 --> 02:11:57,009 now for exercise back to our sequel 5886 02:11:57,009 --> 02:11:57,019 now for exercise back to our sequel 5887 02:11:57,019 --> 02:11:59,080 now for exercise back to our sequel invoicing database write a query to 5888 02:11:59,080 --> 02:11:59,090 invoicing database write a query to 5889 02:11:59,090 --> 02:12:01,120 invoicing database write a query to select the payment from the payments 5890 02:12:01,120 --> 02:12:01,130 select the payment from the payments 5891 02:12:01,130 --> 02:12:03,310 select the payment from the payments table and produce something like this so 5892 02:12:03,310 --> 02:12:03,320 table and produce something like this so 5893 02:12:03,320 --> 02:12:05,919 table and produce something like this so in this table we have a date the client 5894 02:12:05,919 --> 02:12:05,929 in this table we have a date the client 5895 02:12:05,929 --> 02:12:08,200 in this table we have a date the client the amount and the payment method we can 5896 02:12:08,200 --> 02:12:08,210 the amount and the payment method we can 5897 02:12:08,210 --> 02:12:10,479 the amount and the payment method we can see on what date who has paid how much 5898 02:12:10,479 --> 02:12:10,489 see on what date who has paid how much 5899 02:12:10,489 --> 02:12:13,530 see on what date who has paid how much using what payment method 5900 02:12:13,530 --> 02:12:13,540 using what payment method 5901 02:12:13,540 --> 02:12:17,040 using what payment method you 5902 02:12:17,040 --> 02:12:17,050 5903 02:12:17,050 --> 02:12:19,510 alright I'm gonna use that's equal 5904 02:12:19,510 --> 02:12:19,520 alright I'm gonna use that's equal 5905 02:12:19,520 --> 02:12:22,360 alright I'm gonna use that's equal invoicing database and then select 5906 02:12:22,360 --> 02:12:22,370 invoicing database and then select 5907 02:12:22,370 --> 02:12:26,620 invoicing database and then select everything from the payments table join 5908 02:12:26,620 --> 02:12:26,630 everything from the payments table join 5909 02:12:26,630 --> 02:12:30,970 everything from the payments table join it with the clients table using client 5910 02:12:30,970 --> 02:12:30,980 it with the clients table using client 5911 02:12:30,980 --> 02:12:33,400 it with the clients table using client ID because in both these tables we have 5912 02:12:33,400 --> 02:12:33,410 ID because in both these tables we have 5913 02:12:33,410 --> 02:12:35,860 ID because in both these tables we have the client ID column next we need to 5914 02:12:35,860 --> 02:12:35,870 the client ID column next we need to 5915 02:12:35,870 --> 02:12:39,760 the client ID column next we need to join this with payment methods however 5916 02:12:39,760 --> 02:12:39,770 join this with payment methods however 5917 02:12:39,770 --> 02:12:42,040 join this with payment methods however the column name between these two tables 5918 02:12:42,040 --> 02:12:42,050 the column name between these two tables 5919 02:12:42,050 --> 02:12:45,190 the column name between these two tables is different so in the payments table we 5920 02:12:45,190 --> 02:12:45,200 is different so in the payments table we 5921 02:12:45,200 --> 02:12:47,500 is different so in the payments table we have a column called payment method but 5922 02:12:47,500 --> 02:12:47,510 have a column called payment method but 5923 02:12:47,510 --> 02:12:49,750 have a column called payment method but in payment methods table our column is 5924 02:12:49,750 --> 02:12:49,760 in payment methods table our column is 5925 02:12:49,760 --> 02:12:52,480 in payment methods table our column is called payment method ID so here we 5926 02:12:52,480 --> 02:12:52,490 called payment method ID so here we 5927 02:12:52,490 --> 02:12:55,660 called payment method ID so here we cannot use the using keyword and we'll 5928 02:12:55,660 --> 02:12:55,670 cannot use the using keyword and we'll 5929 02:12:55,670 --> 02:12:59,050 cannot use the using keyword and we'll have to use the on clause so on P dot 5930 02:12:59,050 --> 02:12:59,060 have to use the on clause so on P dot 5931 02:12:59,060 --> 02:13:03,550 have to use the on clause so on P dot payment under line method equals P m dot 5932 02:13:03,550 --> 02:13:03,560 payment under line method equals P m dot 5933 02:13:03,560 --> 02:13:07,480 payment under line method equals P m dot payment method ID now let's pick our 5934 02:13:07,480 --> 02:13:07,490 payment method ID now let's pick our 5935 02:13:07,490 --> 02:13:12,190 payment method ID now let's pick our columns so payment that date client that 5936 02:13:12,190 --> 02:13:12,200 columns so payment that date client that 5937 02:13:12,200 --> 02:13:15,670 columns so payment that date client that name and we rename this as client next 5938 02:13:15,670 --> 02:13:15,680 name and we rename this as client next 5939 02:13:15,680 --> 02:13:18,820 name and we rename this as client next we pick the amount and finally the 5940 02:13:18,820 --> 02:13:18,830 we pick the amount and finally the 5941 02:13:18,830 --> 02:13:21,550 we pick the amount and finally the payment method so let's rename that to 5942 02:13:21,550 --> 02:13:21,560 payment method so let's rename that to 5943 02:13:21,560 --> 02:13:25,390 payment method so let's rename that to payment on the line method and execute 5944 02:13:25,390 --> 02:13:25,400 payment on the line method and execute 5945 02:13:25,400 --> 02:13:27,640 payment on the line method and execute the query there you go this is what we 5946 02:13:27,640 --> 02:13:27,650 the query there you go this is what we 5947 02:13:27,650 --> 02:13:30,910 the query there you go this is what we get the date the client the amount and 5948 02:13:30,910 --> 02:13:30,920 get the date the client the amount and 5949 02:13:30,920 --> 02:13:37,120 get the date the client the amount and the payment method 5950 02:13:37,120 --> 02:13:37,130 5951 02:13:37,130 --> 02:13:40,430 in my skill we also have another simpler 5952 02:13:40,430 --> 02:13:40,440 in my skill we also have another simpler 5953 02:13:40,440 --> 02:13:42,800 in my skill we also have another simpler way to join two tables it's called a 5954 02:13:42,800 --> 02:13:42,810 way to join two tables it's called a 5955 02:13:42,810 --> 02:13:45,110 way to join two tables it's called a natural join and it's easier to code but 5956 02:13:45,110 --> 02:13:45,120 natural join and it's easier to code but 5957 02:13:45,120 --> 02:13:46,010 natural join and it's easier to code but it's not something that I recommend 5958 02:13:46,010 --> 02:13:46,020 it's not something that I recommend 5959 02:13:46,020 --> 02:13:48,620 it's not something that I recommend because sometimes it produces unexpected 5960 02:13:48,620 --> 02:13:48,630 because sometimes it produces unexpected 5961 02:13:48,630 --> 02:13:50,420 because sometimes it produces unexpected results but let me quickly show you how 5962 02:13:50,420 --> 02:13:50,430 results but let me quickly show you how 5963 02:13:50,430 --> 02:13:51,140 results but let me quickly show you how it works 5964 02:13:51,140 --> 02:13:51,150 it works 5965 02:13:51,150 --> 02:13:52,910 it works in case you see it somewhere so at least 5966 02:13:52,910 --> 02:13:52,920 in case you see it somewhere so at least 5967 02:13:52,920 --> 02:13:54,920 in case you see it somewhere so at least you're familiar with it so back to the 5968 02:13:54,920 --> 02:13:54,930 you're familiar with it so back to the 5969 02:13:54,930 --> 02:13:57,110 you're familiar with it so back to the previous example let's select everything 5970 02:13:57,110 --> 02:13:57,120 previous example let's select everything 5971 02:13:57,120 --> 02:14:00,410 previous example let's select everything from the orders table now we should do a 5972 02:14:00,410 --> 02:14:00,420 from the orders table now we should do a 5973 02:14:00,420 --> 02:14:03,890 from the orders table now we should do a natural join with the customers table 5974 02:14:03,890 --> 02:14:03,900 natural join with the customers table 5975 02:14:03,900 --> 02:14:06,320 natural join with the customers table now with this natural joins we don't 5976 02:14:06,320 --> 02:14:06,330 now with this natural joins we don't 5977 02:14:06,330 --> 02:14:09,380 now with this natural joins we don't explicitly specify the column names so 5978 02:14:09,380 --> 02:14:09,390 explicitly specify the column names so 5979 02:14:09,390 --> 02:14:10,670 explicitly specify the column names so the database engine will look at these 5980 02:14:10,670 --> 02:14:10,680 the database engine will look at these 5981 02:14:10,680 --> 02:14:13,340 the database engine will look at these two tables I like to join them based on 5982 02:14:13,340 --> 02:14:13,350 two tables I like to join them based on 5983 02:14:13,350 --> 02:14:15,560 two tables I like to join them based on the common columns the columns that have 5984 02:14:15,560 --> 02:14:15,570 the common columns the columns that have 5985 02:14:15,570 --> 02:14:18,140 the common columns the columns that have the same name and that is the reason 5986 02:14:18,140 --> 02:14:18,150 the same name and that is the reason 5987 02:14:18,150 --> 02:14:21,170 the same name and that is the reason this queries shortage right so for 5988 02:14:21,170 --> 02:14:21,180 this queries shortage right so for 5989 02:14:21,180 --> 02:14:22,910 this queries shortage right so for clarity let's pick a couple of columns 5990 02:14:22,910 --> 02:14:22,920 clarity let's pick a couple of columns 5991 02:14:22,920 --> 02:14:27,650 clarity let's pick a couple of columns here oh that order ID and CDOT let's say 5992 02:14:27,650 --> 02:14:27,660 here oh that order ID and CDOT let's say 5993 02:14:27,660 --> 02:14:31,280 here oh that order ID and CDOT let's say first name let's execute the query there 5994 02:14:31,280 --> 02:14:31,290 first name let's execute the query there 5995 02:14:31,290 --> 02:14:35,180 first name let's execute the query there you go so we see all the orders and the 5996 02:14:35,180 --> 02:14:35,190 you go so we see all the orders and the 5997 02:14:35,190 --> 02:14:37,970 you go so we see all the orders and the customers will place them so natural 5998 02:14:37,970 --> 02:14:37,980 customers will place them so natural 5999 02:14:37,980 --> 02:14:40,040 customers will place them so natural joins are really easy to code but they 6000 02:14:40,040 --> 02:14:40,050 joins are really easy to code but they 6001 02:14:40,050 --> 02:14:41,780 joins are really easy to code but they can be a little bit dangerous because 6002 02:14:41,780 --> 02:14:41,790 can be a little bit dangerous because 6003 02:14:41,790 --> 02:14:43,820 can be a little bit dangerous because we're letting the database engine figure 6004 02:14:43,820 --> 02:14:43,830 we're letting the database engine figure 6005 02:14:43,830 --> 02:14:46,220 we're letting the database engine figure out or guess the join we don't have 6006 02:14:46,220 --> 02:14:46,230 out or guess the join we don't have 6007 02:14:46,230 --> 02:14:48,310 out or guess the join we don't have control over it for this very reason 6008 02:14:48,310 --> 02:14:48,320 control over it for this very reason 6009 02:14:48,320 --> 02:14:50,420 control over it for this very reason natural joints can produce unexpected 6010 02:14:50,420 --> 02:14:50,430 natural joints can produce unexpected 6011 02:14:50,430 --> 02:14:52,760 natural joints can produce unexpected results and that's why I discourage you 6012 02:14:52,760 --> 02:14:52,770 results and that's why I discourage you 6013 02:14:52,770 --> 02:14:57,920 results and that's why I discourage you to use them 6014 02:14:57,920 --> 02:14:57,930 6015 02:14:57,930 --> 02:15:00,540 in this tutorial we're going to look at 6016 02:15:00,540 --> 02:15:00,550 in this tutorial we're going to look at 6017 02:15:00,550 --> 02:15:03,540 in this tutorial we're going to look at cross joins in sequa we use cross joins 6018 02:15:03,540 --> 02:15:03,550 cross joins in sequa we use cross joins 6019 02:15:03,550 --> 02:15:06,270 cross joins in sequa we use cross joins to combine or join every record from the 6020 02:15:06,270 --> 02:15:06,280 to combine or join every record from the 6021 02:15:06,280 --> 02:15:08,340 to combine or join every record from the first table with every record in the 6022 02:15:08,340 --> 02:15:08,350 first table with every record in the 6023 02:15:08,350 --> 02:15:11,220 first table with every record in the second table here's an example let's 6024 02:15:11,220 --> 02:15:11,230 second table here's an example let's 6025 02:15:11,230 --> 02:15:14,939 second table here's an example let's select everything from the customers 6026 02:15:14,939 --> 02:15:14,949 select everything from the customers 6027 02:15:14,949 --> 02:15:18,990 select everything from the customers table now here we do a cross join with 6028 02:15:18,990 --> 02:15:19,000 table now here we do a cross join with 6029 02:15:19,000 --> 02:15:22,260 table now here we do a cross join with the product table so every record in the 6030 02:15:22,260 --> 02:15:22,270 the product table so every record in the 6031 02:15:22,270 --> 02:15:24,090 the product table so every record in the customers table will be combined with 6032 02:15:24,090 --> 02:15:24,100 customers table will be combined with 6033 02:15:24,100 --> 02:15:26,400 customers table will be combined with every record and the products table and 6034 02:15:26,400 --> 02:15:26,410 every record and the products table and 6035 02:15:26,410 --> 02:15:29,280 every record and the products table and that is why we don't have a condition 6036 02:15:29,280 --> 02:15:29,290 that is why we don't have a condition 6037 02:15:29,290 --> 02:15:32,280 that is why we don't have a condition here okay so this is what we call a 6038 02:15:32,280 --> 02:15:32,290 here okay so this is what we call a 6039 02:15:32,290 --> 02:15:34,650 here okay so this is what we call a cross join now for clarity let's pick a 6040 02:15:34,650 --> 02:15:34,660 cross join now for clarity let's pick a 6041 02:15:34,660 --> 02:15:37,290 cross join now for clarity let's pick a couple of columns like see that first 6042 02:15:37,290 --> 02:15:37,300 couple of columns like see that first 6043 02:15:37,300 --> 02:15:41,780 couple of columns like see that first name we rename it as customer and then 6044 02:15:41,780 --> 02:15:41,790 name we rename it as customer and then 6045 02:15:41,790 --> 02:15:44,100 name we rename it as customer and then product the name which were renamed to 6046 02:15:44,100 --> 02:15:44,110 product the name which were renamed to 6047 02:15:44,110 --> 02:15:48,720 product the name which were renamed to product also let's sort the result by 6048 02:15:48,720 --> 02:15:48,730 product also let's sort the result by 6049 02:15:48,730 --> 02:15:52,620 product also let's sort the result by customer dot first name now let's 6050 02:15:52,620 --> 02:15:52,630 customer dot first name now let's 6051 02:15:52,630 --> 02:15:55,530 customer dot first name now let's execute the query here's the result of a 6052 02:15:55,530 --> 02:15:55,540 execute the query here's the result of a 6053 02:15:55,540 --> 02:15:59,100 execute the query here's the result of a cross join so first we have amber as the 6054 02:15:59,100 --> 02:15:59,110 cross join so first we have amber as the 6055 02:15:59,110 --> 02:16:00,990 cross join so first we have amber as the customer and here are all the 6056 02:16:00,990 --> 02:16:01,000 customer and here are all the 6057 02:16:01,000 --> 02:16:03,150 customer and here are all the combinations of amber with different 6058 02:16:03,150 --> 02:16:03,160 combinations of amber with different 6059 02:16:03,160 --> 02:16:05,670 combinations of amber with different products next we have Barbara or 6060 02:16:05,670 --> 02:16:05,680 products next we have Barbara or 6061 02:16:05,680 --> 02:16:07,709 products next we have Barbara or whatever it is and again we have the 6062 02:16:07,709 --> 02:16:07,719 whatever it is and again we have the 6063 02:16:07,719 --> 02:16:09,360 whatever it is and again we have the combination of this customer with all 6064 02:16:09,360 --> 02:16:09,370 combination of this customer with all 6065 02:16:09,370 --> 02:16:11,130 combination of this customer with all the products now in this particular 6066 02:16:11,130 --> 02:16:11,140 the products now in this particular 6067 02:16:11,140 --> 02:16:13,170 the products now in this particular example it doesn't really make sense to 6068 02:16:13,170 --> 02:16:13,180 example it doesn't really make sense to 6069 02:16:13,180 --> 02:16:15,600 example it doesn't really make sense to use a cross join a real example for 6070 02:16:15,600 --> 02:16:15,610 use a cross join a real example for 6071 02:16:15,610 --> 02:16:17,790 use a cross join a real example for using cross joins is where you have a 6072 02:16:17,790 --> 02:16:17,800 using cross joins is where you have a 6073 02:16:17,800 --> 02:16:20,880 using cross joins is where you have a table of sizes like small medium large 6074 02:16:20,880 --> 02:16:20,890 table of sizes like small medium large 6075 02:16:20,890 --> 02:16:23,820 table of sizes like small medium large and a table of colors like red blue 6076 02:16:23,820 --> 02:16:23,830 and a table of colors like red blue 6077 02:16:23,830 --> 02:16:25,709 and a table of colors like red blue green whatever and then you want to 6078 02:16:25,709 --> 02:16:25,719 green whatever and then you want to 6079 02:16:25,719 --> 02:16:27,930 green whatever and then you want to combine all the sizes with all the 6080 02:16:27,930 --> 02:16:27,940 combine all the sizes with all the 6081 02:16:27,940 --> 02:16:30,979 combine all the sizes with all the colors that is when you use a cross join 6082 02:16:30,979 --> 02:16:30,989 colors that is when you use a cross join 6083 02:16:30,989 --> 02:16:33,240 colors that is when you use a cross join now what we have here is called the 6084 02:16:33,240 --> 02:16:33,250 now what we have here is called the 6085 02:16:33,250 --> 02:16:36,270 now what we have here is called the explicit syntax for cross join we also 6086 02:16:36,270 --> 02:16:36,280 explicit syntax for cross join we also 6087 02:16:36,280 --> 02:16:38,190 explicit syntax for cross join we also have the implicit syntax which looks 6088 02:16:38,190 --> 02:16:38,200 have the implicit syntax which looks 6089 02:16:38,200 --> 02:16:40,530 have the implicit syntax which looks like this instead of typing out the 6090 02:16:40,530 --> 02:16:40,540 like this instead of typing out the 6091 02:16:40,540 --> 02:16:43,259 like this instead of typing out the cross join which I pad multiple tables 6092 02:16:43,259 --> 02:16:43,269 cross join which I pad multiple tables 6093 02:16:43,269 --> 02:16:46,350 cross join which I pad multiple tables in the front claws so customers and 6094 02:16:46,350 --> 02:16:46,360 in the front claws so customers and 6095 02:16:46,360 --> 02:16:49,620 in the front claws so customers and orders both these queries produce the 6096 02:16:49,620 --> 02:16:49,630 orders both these queries produce the 6097 02:16:49,630 --> 02:16:51,929 orders both these queries produce the same result but I personally prefer to 6098 02:16:51,929 --> 02:16:51,939 same result but I personally prefer to 6099 02:16:51,939 --> 02:16:54,299 same result but I personally prefer to use the explicit syntax because it's 6100 02:16:54,299 --> 02:16:54,309 use the explicit syntax because it's 6101 02:16:54,309 --> 02:16:58,620 use the explicit syntax because it's more clear 6102 02:16:58,620 --> 02:16:58,630 6103 02:16:58,630 --> 02:17:02,220 and here is a simple exercise for you do 6104 02:17:02,220 --> 02:17:02,230 and here is a simple exercise for you do 6105 02:17:02,230 --> 02:17:04,250 and here is a simple exercise for you do a cross join between shippers and 6106 02:17:04,250 --> 02:17:04,260 a cross join between shippers and 6107 02:17:04,260 --> 02:17:07,050 a cross join between shippers and products first do it using the implicit 6108 02:17:07,050 --> 02:17:07,060 products first do it using the implicit 6109 02:17:07,060 --> 02:17:09,450 products first do it using the implicit syntax and then using the explicit 6110 02:17:09,450 --> 02:17:09,460 syntax and then using the explicit 6111 02:17:09,460 --> 02:17:11,700 syntax and then using the explicit syntax it's pretty straightforward I 6112 02:17:11,700 --> 02:17:11,710 syntax it's pretty straightforward I 6113 02:17:11,710 --> 02:17:13,230 syntax it's pretty straightforward I just want you to get your hands dirty in 6114 02:17:13,230 --> 02:17:13,240 just want you to get your hands dirty in 6115 02:17:13,240 --> 02:17:16,660 just want you to get your hands dirty in the code and get used to this syntax 6116 02:17:16,660 --> 02:17:16,670 the code and get used to this syntax 6117 02:17:16,670 --> 02:17:19,930 the code and get used to this syntax you 6118 02:17:19,930 --> 02:17:19,940 6119 02:17:19,940 --> 02:17:22,040 alright first I'm gonna use the implicit 6120 02:17:22,040 --> 02:17:22,050 alright first I'm gonna use the implicit 6121 02:17:22,050 --> 02:17:23,839 alright first I'm gonna use the implicit syntax and then I will show you the 6122 02:17:23,839 --> 02:17:23,849 syntax and then I will show you the 6123 02:17:23,849 --> 02:17:26,570 syntax and then I will show you the explicit syntax so let's start by 6124 02:17:26,570 --> 02:17:26,580 explicit syntax so let's start by 6125 02:17:26,580 --> 02:17:28,759 explicit syntax so let's start by selecting everything from two tables 6126 02:17:28,759 --> 02:17:28,769 selecting everything from two tables 6127 02:17:28,769 --> 02:17:33,589 selecting everything from two tables shippers and products now for clarity 6128 02:17:33,589 --> 02:17:33,599 shippers and products now for clarity 6129 02:17:33,599 --> 02:17:36,290 shippers and products now for clarity let's pick two columns shipper that name 6130 02:17:36,290 --> 02:17:36,300 let's pick two columns shipper that name 6131 02:17:36,300 --> 02:17:39,680 let's pick two columns shipper that name which we renamed to shipper and product 6132 02:17:39,680 --> 02:17:39,690 which we renamed to shipper and product 6133 02:17:39,690 --> 02:17:41,919 which we renamed to shipper and product name which we renamed to product and 6134 02:17:41,919 --> 02:17:41,929 name which we renamed to product and 6135 02:17:41,929 --> 02:17:44,570 name which we renamed to product and finally let's order everything by 6136 02:17:44,570 --> 02:17:44,580 finally let's order everything by 6137 02:17:44,580 --> 02:17:47,770 finally let's order everything by shipper the name let's execute the query 6138 02:17:47,770 --> 02:17:47,780 shipper the name let's execute the query 6139 02:17:47,780 --> 02:17:51,440 shipper the name let's execute the query this is what we get so the combination 6140 02:17:51,440 --> 02:17:51,450 this is what we get so the combination 6141 02:17:51,450 --> 02:17:53,450 this is what we get so the combination of all shippers and all products 6142 02:17:53,450 --> 02:17:53,460 of all shippers and all products 6143 02:17:53,460 --> 02:17:56,120 of all shippers and all products beautiful now let's use the explicit 6144 02:17:56,120 --> 02:17:56,130 beautiful now let's use the explicit 6145 02:17:56,130 --> 02:17:59,150 beautiful now let's use the explicit syntax so we select everything from the 6146 02:17:59,150 --> 02:17:59,160 syntax so we select everything from the 6147 02:17:59,160 --> 02:18:01,250 syntax so we select everything from the base table in this case shippers and 6148 02:18:01,250 --> 02:18:01,260 base table in this case shippers and 6149 02:18:01,260 --> 02:18:05,320 base table in this case shippers and then do a cross join with products that 6150 02:18:05,320 --> 02:18:05,330 then do a cross join with products that 6151 02:18:05,330 --> 02:18:13,129 then do a cross join with products that produces exactly the same result 6152 02:18:13,129 --> 02:18:13,139 6153 02:18:13,139 --> 02:18:16,020 we covered everything about joints you 6154 02:18:16,020 --> 02:18:16,030 we covered everything about joints you 6155 02:18:16,030 --> 02:18:17,429 we covered everything about joints you learn that with joints we can combine 6156 02:18:17,429 --> 02:18:17,439 learn that with joints we can combine 6157 02:18:17,439 --> 02:18:20,129 learn that with joints we can combine columns from multiple tables but in 6158 02:18:20,129 --> 02:18:20,139 columns from multiple tables but in 6159 02:18:20,139 --> 02:18:22,560 columns from multiple tables but in sequel we can also combine rows from 6160 02:18:22,560 --> 02:18:22,570 sequel we can also combine rows from 6161 02:18:22,570 --> 02:18:24,719 sequel we can also combine rows from multiple tables and this is extremely 6162 02:18:24,719 --> 02:18:24,729 multiple tables and this is extremely 6163 02:18:24,729 --> 02:18:26,780 multiple tables and this is extremely powerful let me show you how that works 6164 02:18:26,780 --> 02:18:26,790 powerful let me show you how that works 6165 02:18:26,790 --> 02:18:29,370 powerful let me show you how that works first let's have a quick look at our 6166 02:18:29,370 --> 02:18:29,380 first let's have a quick look at our 6167 02:18:29,380 --> 02:18:31,350 first let's have a quick look at our orders table so select everything from 6168 02:18:31,350 --> 02:18:31,360 orders table so select everything from 6169 02:18:31,360 --> 02:18:34,589 orders table so select everything from the orders table now if you look at the 6170 02:18:34,589 --> 02:18:34,599 the orders table now if you look at the 6171 02:18:34,599 --> 02:18:38,160 the orders table now if you look at the data we can see that the first order was 6172 02:18:38,160 --> 02:18:38,170 data we can see that the first order was 6173 02:18:38,170 --> 02:18:41,339 data we can see that the first order was placed in the current year 2019 all the 6174 02:18:41,339 --> 02:18:41,349 placed in the current year 2019 all the 6175 02:18:41,349 --> 02:18:43,259 placed in the current year 2019 all the other orders were placed in previous 6176 02:18:43,259 --> 02:18:43,269 other orders were placed in previous 6177 02:18:43,269 --> 02:18:45,330 other orders were placed in previous years now let's say we want to create a 6178 02:18:45,330 --> 02:18:45,340 years now let's say we want to create a 6179 02:18:45,340 --> 02:18:47,820 years now let's say we want to create a report get all the orders are next to 6180 02:18:47,820 --> 02:18:47,830 report get all the orders are next to 6181 02:18:47,830 --> 02:18:50,339 report get all the orders are next to each order add a label if the order is 6182 02:18:50,339 --> 02:18:50,349 each order add a label if the order is 6183 02:18:50,349 --> 02:18:52,320 each order add a label if the order is placed in the current year the label is 6184 02:18:52,320 --> 02:18:52,330 placed in the current year the label is 6185 02:18:52,330 --> 02:18:54,390 placed in the current year the label is going to be active and if the order was 6186 02:18:54,390 --> 02:18:54,400 going to be active and if the order was 6187 02:18:54,400 --> 02:18:56,370 going to be active and if the order was placed in previous years we want to 6188 02:18:56,370 --> 02:18:56,380 placed in previous years we want to 6189 02:18:56,380 --> 02:19:00,209 placed in previous years we want to label it as archived so let's change our 6190 02:19:00,209 --> 02:19:00,219 label it as archived so let's change our 6191 02:19:00,219 --> 02:19:03,390 label it as archived so let's change our query and add a condition here first we 6192 02:19:03,390 --> 02:19:03,400 query and add a condition here first we 6193 02:19:03,400 --> 02:19:04,740 query and add a condition here first we want to get all the orders in the 6194 02:19:04,740 --> 02:19:04,750 want to get all the orders in the 6195 02:19:04,750 --> 02:19:08,730 want to get all the orders in the current here so we're order date is 6196 02:19:08,730 --> 02:19:08,740 current here so we're order date is 6197 02:19:08,740 --> 02:19:14,009 current here so we're order date is greater than or equal to 2019 0 1 0 1 I 6198 02:19:14,009 --> 02:19:14,019 greater than or equal to 2019 0 1 0 1 I 6199 02:19:14,019 --> 02:19:16,169 greater than or equal to 2019 0 1 0 1 I just want to highlight that this is not 6200 02:19:16,169 --> 02:19:16,179 just want to highlight that this is not 6201 02:19:16,179 --> 02:19:18,270 just want to highlight that this is not the ideal way to get the orders in the 6202 02:19:18,270 --> 02:19:18,280 the ideal way to get the orders in the 6203 02:19:18,280 --> 02:19:19,770 the ideal way to get the orders in the current year because here we have 6204 02:19:19,770 --> 02:19:19,780 current year because here we have 6205 02:19:19,780 --> 02:19:22,799 current year because here we have hard-coded 2019 so if we execute this 6206 02:19:22,799 --> 02:19:22,809 hard-coded 2019 so if we execute this 6207 02:19:22,809 --> 02:19:24,570 hard-coded 2019 so if we execute this query next year we're not gonna get the 6208 02:19:24,570 --> 02:19:24,580 query next year we're not gonna get the 6209 02:19:24,580 --> 02:19:26,429 query next year we're not gonna get the right result but don't worry about this 6210 02:19:26,429 --> 02:19:26,439 right result but don't worry about this 6211 02:19:26,439 --> 02:19:28,140 right result but don't worry about this for now later in the course I will show 6212 02:19:28,140 --> 02:19:28,150 for now later in the course I will show 6213 02:19:28,150 --> 02:19:29,790 for now later in the course I will show you how to get the orders in the current 6214 02:19:29,790 --> 02:19:29,800 you how to get the orders in the current 6215 02:19:29,800 --> 02:19:33,150 you how to get the orders in the current year without hard coding a date here so 6216 02:19:33,150 --> 02:19:33,160 year without hard coding a date here so 6217 02:19:33,160 --> 02:19:36,360 year without hard coding a date here so let's execute this query now we get only 6218 02:19:36,360 --> 02:19:36,370 let's execute this query now we get only 6219 02:19:36,370 --> 02:19:39,719 let's execute this query now we get only one order let's hand pick a couple of 6220 02:19:39,719 --> 02:19:39,729 one order let's hand pick a couple of 6221 02:19:39,729 --> 02:19:45,480 one order let's hand pick a couple of columns here so order ID and order date 6222 02:19:45,480 --> 02:19:45,490 columns here so order ID and order date 6223 02:19:45,490 --> 02:19:48,480 columns here so order ID and order date and also I want to add a string literal 6224 02:19:48,480 --> 02:19:48,490 and also I want to add a string literal 6225 02:19:48,490 --> 02:19:53,310 and also I want to add a string literal here like active right let's execute 6226 02:19:53,310 --> 02:19:53,320 here like active right let's execute 6227 02:19:53,320 --> 02:19:55,740 here like active right let's execute this query this is what we get we have 6228 02:19:55,740 --> 02:19:55,750 this query this is what we get we have 6229 02:19:55,750 --> 02:19:57,240 this query this is what we get we have three columns order ID 6230 02:19:57,240 --> 02:19:57,250 three columns order ID 6231 02:19:57,250 --> 02:20:00,300 three columns order ID order date and active and in this column 6232 02:20:00,300 --> 02:20:00,310 order date and active and in this column 6233 02:20:00,310 --> 02:20:02,370 order date and active and in this column currently we have this string value 6234 02:20:02,370 --> 02:20:02,380 currently we have this string value 6235 02:20:02,380 --> 02:20:06,320 currently we have this string value active now let's rename this column to 6236 02:20:06,320 --> 02:20:06,330 active now let's rename this column to 6237 02:20:06,330 --> 02:20:10,710 active now let's rename this column to status and execute the query that is 6238 02:20:10,710 --> 02:20:10,720 status and execute the query that is 6239 02:20:10,720 --> 02:20:13,260 status and execute the query that is better now we want to write another 6240 02:20:13,260 --> 02:20:13,270 better now we want to write another 6241 02:20:13,270 --> 02:20:15,840 better now we want to write another query similar to this that will return 6242 02:20:15,840 --> 02:20:15,850 query similar to this that will return 6243 02:20:15,850 --> 02:20:17,760 query similar to this that will return the orders in the previous years but 6244 02:20:17,760 --> 02:20:17,770 the orders in the previous years but 6245 02:20:17,770 --> 02:20:21,330 the orders in the previous years but with a different label archive so to 6246 02:20:21,330 --> 02:20:21,340 with a different label archive so to 6247 02:20:21,340 --> 02:20:22,770 with a different label archive so to save time 6248 02:20:22,770 --> 02:20:22,780 save time 6249 02:20:22,780 --> 02:20:26,430 save time I'm gonna copy this V Alliance and paste 6250 02:20:26,430 --> 02:20:26,440 I'm gonna copy this V Alliance and paste 6251 02:20:26,440 --> 02:20:28,860 I'm gonna copy this V Alliance and paste them right after our first select 6252 02:20:28,860 --> 02:20:28,870 them right after our first select 6253 02:20:28,870 --> 02:20:30,660 them right after our first select statement now note that here we have a 6254 02:20:30,660 --> 02:20:30,670 statement now note that here we have a 6255 02:20:30,670 --> 02:20:32,370 statement now note that here we have a syntax error because we didn't terminate 6256 02:20:32,370 --> 02:20:32,380 syntax error because we didn't terminate 6257 02:20:32,380 --> 02:20:34,860 syntax error because we didn't terminate the first select statement with a 6258 02:20:34,860 --> 02:20:34,870 the first select statement with a 6259 02:20:34,870 --> 02:20:36,960 the first select statement with a semicolon but don't worry about it we're 6260 02:20:36,960 --> 02:20:36,970 semicolon but don't worry about it we're 6261 02:20:36,970 --> 02:20:39,420 semicolon but don't worry about it we're gonna get back to this in a second so 6262 02:20:39,420 --> 02:20:39,430 gonna get back to this in a second so 6263 02:20:39,430 --> 02:20:41,490 gonna get back to this in a second so for the second query we want to return a 6264 02:20:41,490 --> 02:20:41,500 for the second query we want to return a 6265 02:20:41,500 --> 02:20:44,610 for the second query we want to return a different label archive and you wanna 6266 02:20:44,610 --> 02:20:44,620 different label archive and you wanna 6267 02:20:44,620 --> 02:20:48,740 different label archive and you wanna change our condition to less than 2019 6268 02:20:48,740 --> 02:20:48,750 change our condition to less than 2019 6269 02:20:48,750 --> 02:20:52,290 change our condition to less than 2019 now select only these few lines and 6270 02:20:52,290 --> 02:20:52,300 now select only these few lines and 6271 02:20:52,300 --> 02:20:54,900 now select only these few lines and execute this query either by clicking on 6272 02:20:54,900 --> 02:20:54,910 execute this query either by clicking on 6273 02:20:54,910 --> 02:20:57,150 execute this query either by clicking on this icon here or using the keyboard 6274 02:20:57,150 --> 02:20:57,160 this icon here or using the keyboard 6275 02:20:57,160 --> 02:20:58,710 this icon here or using the keyboard shortcut that you learned earlier in the 6276 02:20:58,710 --> 02:20:58,720 shortcut that you learned earlier in the 6277 02:20:58,720 --> 02:21:04,050 shortcut that you learned earlier in the course so there you go here are all the 6278 02:21:04,050 --> 02:21:04,060 course so there you go here are all the 6279 02:21:04,060 --> 02:21:06,060 course so there you go here are all the orders from the previous years with the 6280 02:21:06,060 --> 02:21:06,070 orders from the previous years with the 6281 02:21:06,070 --> 02:21:09,390 orders from the previous years with the label archive this query returns nine 6282 02:21:09,390 --> 02:21:09,400 label archive this query returns nine 6283 02:21:09,400 --> 02:21:11,940 label archive this query returns nine records the previous query returned one 6284 02:21:11,940 --> 02:21:11,950 records the previous query returned one 6285 02:21:11,950 --> 02:21:14,970 records the previous query returned one record now using the Union operator we 6286 02:21:14,970 --> 02:21:14,980 record now using the Union operator we 6287 02:21:14,980 --> 02:21:16,950 record now using the Union operator we can combine data from these two queries 6288 02:21:16,950 --> 02:21:16,960 can combine data from these two queries 6289 02:21:16,960 --> 02:21:22,080 can combine data from these two queries so in between our select statements we 6290 02:21:22,080 --> 02:21:22,090 so in between our select statements we 6291 02:21:22,090 --> 02:21:24,870 so in between our select statements we type out Union now let's execute the 6292 02:21:24,870 --> 02:21:24,880 type out Union now let's execute the 6293 02:21:24,880 --> 02:21:28,290 type out Union now let's execute the query one more time so here's our first 6294 02:21:28,290 --> 02:21:28,300 query one more time so here's our first 6295 02:21:28,300 --> 02:21:30,210 query one more time so here's our first order in the current year that is active 6296 02:21:30,210 --> 02:21:30,220 order in the current year that is active 6297 02:21:30,220 --> 02:21:32,670 order in the current year that is active and below that we have all the orders in 6298 02:21:32,670 --> 02:21:32,680 and below that we have all the orders in 6299 02:21:32,680 --> 02:21:34,770 and below that we have all the orders in the previous years so using the Union 6300 02:21:34,770 --> 02:21:34,780 the previous years so using the Union 6301 02:21:34,780 --> 02:21:36,960 the previous years so using the Union operator we can combine records from 6302 02:21:36,960 --> 02:21:36,970 operator we can combine records from 6303 02:21:36,970 --> 02:21:38,910 operator we can combine records from multiple queries now in this example 6304 02:21:38,910 --> 02:21:38,920 multiple queries now in this example 6305 02:21:38,920 --> 02:21:41,310 multiple queries now in this example both our queries are against the same 6306 02:21:41,310 --> 02:21:41,320 both our queries are against the same 6307 02:21:41,320 --> 02:21:43,170 both our queries are against the same table but we can also have queries 6308 02:21:43,170 --> 02:21:43,180 table but we can also have queries 6309 02:21:43,180 --> 02:21:45,030 table but we can also have queries against different tables and then 6310 02:21:45,030 --> 02:21:45,040 against different tables and then 6311 02:21:45,040 --> 02:21:47,520 against different tables and then combine the result into one result set 6312 02:21:47,520 --> 02:21:47,530 combine the result into one result set 6313 02:21:47,530 --> 02:21:50,820 combine the result into one result set let me show you another example so I'm 6314 02:21:50,820 --> 02:21:50,830 let me show you another example so I'm 6315 02:21:50,830 --> 02:21:52,830 let me show you another example so I'm gonna delete everything here let's 6316 02:21:52,830 --> 02:21:52,840 gonna delete everything here let's 6317 02:21:52,840 --> 02:21:57,090 gonna delete everything here let's select the first name from the customers 6318 02:21:57,090 --> 02:21:57,100 select the first name from the customers 6319 02:21:57,100 --> 02:21:59,840 select the first name from the customers table and then we can union that with 6320 02:21:59,840 --> 02:21:59,850 table and then we can union that with 6321 02:21:59,850 --> 02:22:03,930 table and then we can union that with select the name from the shippers table 6322 02:22:03,930 --> 02:22:03,940 select the name from the shippers table 6323 02:22:03,940 --> 02:22:07,620 select the name from the shippers table let's execute the query so in one result 6324 02:22:07,620 --> 02:22:07,630 let's execute the query so in one result 6325 02:22:07,630 --> 02:22:10,740 let's execute the query so in one result set we can see all the customers and all 6326 02:22:10,740 --> 02:22:10,750 set we can see all the customers and all 6327 02:22:10,750 --> 02:22:12,960 set we can see all the customers and all the shippers as far as I know there is 6328 02:22:12,960 --> 02:22:12,970 the shippers as far as I know there is 6329 02:22:12,970 --> 02:22:14,700 the shippers as far as I know there is no real word use case for this 6330 02:22:14,700 --> 02:22:14,710 no real word use case for this 6331 02:22:14,710 --> 02:22:16,620 no real word use case for this particular query but what I want to 6332 02:22:16,620 --> 02:22:16,630 particular query but what I want to 6333 02:22:16,630 --> 02:22:18,600 particular query but what I want to point out is that with Union you can 6334 02:22:18,600 --> 02:22:18,610 point out is that with Union you can 6335 02:22:18,610 --> 02:22:20,640 point out is that with Union you can combine results from multiple queries 6336 02:22:20,640 --> 02:22:20,650 combine results from multiple queries 6337 02:22:20,650 --> 02:22:22,950 combine results from multiple queries this queries can be against the same 6338 02:22:22,950 --> 02:22:22,960 this queries can be against the same 6339 02:22:22,960 --> 02:22:26,010 this queries can be against the same table or different tables in your 6340 02:22:26,010 --> 02:22:26,020 table or different tables in your 6341 02:22:26,020 --> 02:22:27,870 table or different tables in your database you could have a table like 6342 02:22:27,870 --> 02:22:27,880 database you could have a table like 6343 02:22:27,880 --> 02:22:30,370 database you could have a table like archived orders and 6344 02:22:30,370 --> 02:22:30,380 archived orders and 6345 02:22:30,380 --> 02:22:33,010 archived orders and another table like orders and then you 6346 02:22:33,010 --> 02:22:33,020 another table like orders and then you 6347 02:22:33,020 --> 02:22:34,660 another table like orders and then you could combine all the archived and 6348 02:22:34,660 --> 02:22:34,670 could combine all the archived and 6349 02:22:34,670 --> 02:22:37,929 could combine all the archived and active orders into one result set just 6350 02:22:37,929 --> 02:22:37,939 active orders into one result set just 6351 02:22:37,939 --> 02:22:40,030 active orders into one result set just remember that the number of columns that 6352 02:22:40,030 --> 02:22:40,040 remember that the number of columns that 6353 02:22:40,040 --> 02:22:42,160 remember that the number of columns that each query returns should be equal 6354 02:22:42,160 --> 02:22:42,170 each query returns should be equal 6355 02:22:42,170 --> 02:22:43,270 each query returns should be equal otherwise you're going to get an error 6356 02:22:43,270 --> 02:22:43,280 otherwise you're going to get an error 6357 02:22:43,280 --> 02:22:45,940 otherwise you're going to get an error for example let's select the first-name 6358 02:22:45,940 --> 02:22:45,950 for example let's select the first-name 6359 02:22:45,950 --> 02:22:49,570 for example let's select the first-name and lastname from customers and then 6360 02:22:49,570 --> 02:22:49,580 and lastname from customers and then 6361 02:22:49,580 --> 02:22:53,500 and lastname from customers and then Union that with the name of shippers let 6362 02:22:53,500 --> 02:22:53,510 Union that with the name of shippers let 6363 02:22:53,510 --> 02:22:55,060 Union that with the name of shippers let me execute this query we'll get an error 6364 02:22:55,060 --> 02:22:55,070 me execute this query we'll get an error 6365 02:22:55,070 --> 02:22:56,830 me execute this query we'll get an error because the first part of this query 6366 02:22:56,830 --> 02:22:56,840 because the first part of this query 6367 02:22:56,840 --> 02:22:59,230 because the first part of this query returns two columns but the second part 6368 02:22:59,230 --> 02:22:59,240 returns two columns but the second part 6369 02:22:59,240 --> 02:23:02,200 returns two columns but the second part returns one column so MySQL doesn't know 6370 02:23:02,200 --> 02:23:02,210 returns one column so MySQL doesn't know 6371 02:23:02,210 --> 02:23:04,780 returns one column so MySQL doesn't know how to combine these records and one 6372 02:23:04,780 --> 02:23:04,790 how to combine these records and one 6373 02:23:04,790 --> 02:23:05,980 how to combine these records and one last thing before we finish this 6374 02:23:05,980 --> 02:23:05,990 last thing before we finish this 6375 02:23:05,990 --> 02:23:08,910 last thing before we finish this tutorial if you look at the result here 6376 02:23:08,910 --> 02:23:08,920 tutorial if you look at the result here 6377 02:23:08,920 --> 02:23:12,070 tutorial if you look at the result here the name of this column is based on the 6378 02:23:12,070 --> 02:23:12,080 the name of this column is based on the 6379 02:23:12,080 --> 02:23:14,139 the name of this column is based on the first Quay so the first query returns 6380 02:23:14,139 --> 02:23:14,149 first Quay so the first query returns 6381 02:23:14,149 --> 02:23:16,210 first Quay so the first query returns first name and that's why this column is 6382 02:23:16,210 --> 02:23:16,220 first name and that's why this column is 6383 02:23:16,220 --> 02:23:19,150 first name and that's why this column is called first name if we change the order 6384 02:23:19,150 --> 02:23:19,160 called first name if we change the order 6385 02:23:19,160 --> 02:23:21,969 called first name if we change the order of this queries and move this Union up 6386 02:23:21,969 --> 02:23:21,979 of this queries and move this Union up 6387 02:23:21,979 --> 02:23:26,380 of this queries and move this Union up here now let's run this query as you can 6388 02:23:26,380 --> 02:23:26,390 here now let's run this query as you can 6389 02:23:26,390 --> 02:23:27,550 here now let's run this query as you can see our column is called 6390 02:23:27,550 --> 02:23:27,560 see our column is called 6391 02:23:27,560 --> 02:23:29,740 see our column is called name so whatever we have in the first 6392 02:23:29,740 --> 02:23:29,750 name so whatever we have in the first 6393 02:23:29,750 --> 02:23:31,810 name so whatever we have in the first query is used to determine the name of 6394 02:23:31,810 --> 02:23:31,820 query is used to determine the name of 6395 02:23:31,820 --> 02:23:33,850 query is used to determine the name of these columns here we can also rename 6396 02:23:33,850 --> 02:23:33,860 these columns here we can also rename 6397 02:23:33,860 --> 02:23:37,929 these columns here we can also rename the column to let's say full name there 6398 02:23:37,929 --> 02:23:37,939 the column to let's say full name there 6399 02:23:37,939 --> 02:23:42,689 the column to let's say full name there you go 6400 02:23:42,689 --> 02:23:42,699 6401 02:23:42,699 --> 02:23:45,040 all right here's your exercise for this 6402 02:23:45,040 --> 02:23:45,050 all right here's your exercise for this 6403 02:23:45,050 --> 02:23:47,500 all right here's your exercise for this tutorial write a query to produce this 6404 02:23:47,500 --> 02:23:47,510 tutorial write a query to produce this 6405 02:23:47,510 --> 02:23:49,090 tutorial write a query to produce this report so here we have four columns 6406 02:23:49,090 --> 02:23:49,100 report so here we have four columns 6407 02:23:49,100 --> 02:23:52,659 report so here we have four columns customer ID first name points and type 6408 02:23:52,659 --> 02:23:52,669 customer ID first name points and type 6409 02:23:52,669 --> 02:23:55,090 customer ID first name points and type as you know we don't have this column in 6410 02:23:55,090 --> 02:23:55,100 as you know we don't have this column in 6411 02:23:55,100 --> 02:23:56,859 as you know we don't have this column in the customers table so we have 6412 02:23:56,859 --> 02:23:56,869 the customers table so we have 6413 02:23:56,869 --> 02:23:58,599 the customers table so we have calculated the values in this column 6414 02:23:58,599 --> 02:23:58,609 calculated the values in this column 6415 02:23:58,609 --> 02:24:02,229 calculated the values in this column based on the points each customer has if 6416 02:24:02,229 --> 02:24:02,239 based on the points each customer has if 6417 02:24:02,239 --> 02:24:04,449 based on the points each customer has if they have less than 2000 points their 6418 02:24:04,449 --> 02:24:04,459 they have less than 2000 points their 6419 02:24:04,459 --> 02:24:07,630 they have less than 2000 points their type is bronze if they have between 2000 6420 02:24:07,630 --> 02:24:07,640 type is bronze if they have between 2000 6421 02:24:07,640 --> 02:24:09,880 type is bronze if they have between 2000 to 3000 points there are silver 6422 02:24:09,880 --> 02:24:09,890 to 3000 points there are silver 6423 02:24:09,890 --> 02:24:11,829 to 3000 points there are silver customers and if they have more than 6424 02:24:11,829 --> 02:24:11,839 customers and if they have more than 6425 02:24:11,839 --> 02:24:14,529 customers and if they have more than 3000 points there are gold customers 6426 02:24:14,529 --> 02:24:14,539 3000 points there are gold customers 6427 02:24:14,539 --> 02:24:16,659 3000 points there are gold customers also note that here we have sorted the 6428 02:24:16,659 --> 02:24:16,669 also note that here we have sorted the 6429 02:24:16,669 --> 02:24:19,239 also note that here we have sorted the result by the first name so go ahead and 6430 02:24:19,239 --> 02:24:19,249 result by the first name so go ahead and 6431 02:24:19,249 --> 02:24:22,011 result by the first name so go ahead and spend two minutes to write this Kuei 6432 02:24:22,011 --> 02:24:22,021 spend two minutes to write this Kuei 6433 02:24:22,021 --> 02:24:25,461 spend two minutes to write this Kuei you 6434 02:24:25,461 --> 02:24:25,471 6435 02:24:25,471 --> 02:24:27,781 alright first let's get the bronze 6436 02:24:27,781 --> 02:24:27,791 alright first let's get the bronze 6437 02:24:27,791 --> 02:24:30,201 alright first let's get the bronze customers so select everything from 6438 02:24:30,201 --> 02:24:30,211 customers so select everything from 6439 02:24:30,211 --> 02:24:34,531 customers so select everything from customers where points is less than 6440 02:24:34,531 --> 02:24:34,541 customers where points is less than 6441 02:24:34,541 --> 02:24:37,711 customers where points is less than 2,000 now here we're gonna pick three 6442 02:24:37,711 --> 02:24:37,721 2,000 now here we're gonna pick three 6443 02:24:37,721 --> 02:24:41,720 2,000 now here we're gonna pick three columns customer ID first name and 6444 02:24:41,720 --> 02:24:41,730 columns customer ID first name and 6445 02:24:41,730 --> 02:24:45,211 columns customer ID first name and points and finally we add and you call 6446 02:24:45,211 --> 02:24:45,221 points and finally we add and you call 6447 02:24:45,221 --> 02:24:49,321 points and finally we add and you call them with a string literal bronze let's 6448 02:24:49,321 --> 02:24:49,331 them with a string literal bronze let's 6449 02:24:49,331 --> 02:24:50,841 them with a string literal bronze let's run this query and see what we get so 6450 02:24:50,841 --> 02:24:50,851 run this query and see what we get so 6451 02:24:50,851 --> 02:24:53,970 run this query and see what we get so these are all the bronze customers but 6452 02:24:53,970 --> 02:24:53,980 these are all the bronze customers but 6453 02:24:53,980 --> 02:24:55,770 these are all the bronze customers but the name of this column is bronze we 6454 02:24:55,770 --> 02:24:55,780 the name of this column is bronze we 6455 02:24:55,780 --> 02:24:57,871 the name of this column is bronze we don't want that so let's rename this to 6456 02:24:57,871 --> 02:24:57,881 don't want that so let's rename this to 6457 02:24:57,881 --> 02:25:00,930 don't want that so let's rename this to type now this is off the screen so I'm 6458 02:25:00,930 --> 02:25:00,940 type now this is off the screen so I'm 6459 02:25:00,940 --> 02:25:03,390 type now this is off the screen so I'm gonna break this up into multiple lines 6460 02:25:03,390 --> 02:25:03,400 gonna break this up into multiple lines 6461 02:25:03,400 --> 02:25:05,520 gonna break this up into multiple lines that makes our query cleaner and easier 6462 02:25:05,520 --> 02:25:05,530 that makes our query cleaner and easier 6463 02:25:05,530 --> 02:25:09,631 that makes our query cleaner and easier to read so there you go let's run the 6464 02:25:09,631 --> 02:25:09,641 to read so there you go let's run the 6465 02:25:09,641 --> 02:25:11,761 to read so there you go let's run the query one more time now the column is 6466 02:25:11,761 --> 02:25:11,771 query one more time now the column is 6467 02:25:11,771 --> 02:25:14,701 query one more time now the column is called type beautiful now we should do a 6468 02:25:14,701 --> 02:25:14,711 called type beautiful now we should do a 6469 02:25:14,711 --> 02:25:19,051 called type beautiful now we should do a union and repeat this query but extract 6470 02:25:19,051 --> 02:25:19,061 union and repeat this query but extract 6471 02:25:19,061 --> 02:25:21,511 union and repeat this query but extract the silver customers so I'm gonna paste 6472 02:25:21,511 --> 02:25:21,521 the silver customers so I'm gonna paste 6473 02:25:21,521 --> 02:25:24,211 the silver customers so I'm gonna paste this query here and then make a couple 6474 02:25:24,211 --> 02:25:24,221 this query here and then make a couple 6475 02:25:24,221 --> 02:25:26,701 this query here and then make a couple of changes here I'm gonna replace bronze 6476 02:25:26,701 --> 02:25:26,711 of changes here I'm gonna replace bronze 6477 02:25:26,711 --> 02:25:30,171 of changes here I'm gonna replace bronze with silver and change the condition to 6478 02:25:30,171 --> 02:25:30,181 with silver and change the condition to 6479 02:25:30,181 --> 02:25:34,860 with silver and change the condition to between 2000 and 3000 let's run our 6480 02:25:34,860 --> 02:25:34,870 between 2000 and 3000 let's run our 6481 02:25:34,870 --> 02:25:38,730 between 2000 and 3000 let's run our query and see what we get so we have all 6482 02:25:38,730 --> 02:25:38,740 query and see what we get so we have all 6483 02:25:38,740 --> 02:25:41,100 query and see what we get so we have all the bronze customers first followed by 6484 02:25:41,100 --> 02:25:41,110 the bronze customers first followed by 6485 02:25:41,110 --> 02:25:43,591 the bronze customers first followed by all the silver customers so the order of 6486 02:25:43,591 --> 02:25:43,601 all the silver customers so the order of 6487 02:25:43,601 --> 02:25:45,690 all the silver customers so the order of these records are based on our queries 6488 02:25:45,690 --> 02:25:45,700 these records are based on our queries 6489 02:25:45,700 --> 02:25:47,491 these records are based on our queries in our first query we got the bronze 6490 02:25:47,491 --> 02:25:47,501 in our first query we got the bronze 6491 02:25:47,501 --> 02:25:49,650 in our first query we got the bronze customers that's why they are list at 6492 02:25:49,650 --> 02:25:49,660 customers that's why they are list at 6493 02:25:49,660 --> 02:25:51,900 customers that's why they are list at first but this is not what we want we 6494 02:25:51,900 --> 02:25:51,910 first but this is not what we want we 6495 02:25:51,910 --> 02:25:54,270 first but this is not what we want we want to order the result by the first 6496 02:25:54,270 --> 02:25:54,280 want to order the result by the first 6497 02:25:54,280 --> 02:25:57,541 want to order the result by the first name of our customers so let's apply an 6498 02:25:57,541 --> 02:25:57,551 name of our customers so let's apply an 6499 02:25:57,551 --> 02:26:01,831 name of our customers so let's apply an order by at the end so order by first 6500 02:26:01,831 --> 02:26:01,841 order by at the end so order by first 6501 02:26:01,841 --> 02:26:04,110 order by at the end so order by first name now there is one more piece 6502 02:26:04,110 --> 02:26:04,120 name now there is one more piece 6503 02:26:04,120 --> 02:26:06,421 name now there is one more piece remaining we should do a union one more 6504 02:26:06,421 --> 02:26:06,431 remaining we should do a union one more 6505 02:26:06,431 --> 02:26:09,091 remaining we should do a union one more time and wait the query to get the gold 6506 02:26:09,091 --> 02:26:09,101 time and wait the query to get the gold 6507 02:26:09,101 --> 02:26:11,310 time and wait the query to get the gold customers so I'm gonna select these few 6508 02:26:11,310 --> 02:26:11,320 customers so I'm gonna select these few 6509 02:26:11,320 --> 02:26:16,881 customers so I'm gonna select these few lines and paste them here 6510 02:26:16,881 --> 02:26:16,891 lines and paste them here 6511 02:26:16,891 --> 02:26:21,111 lines and paste them here now let's change silver to gold and the 6512 02:26:21,111 --> 02:26:21,121 now let's change silver to gold and the 6513 02:26:21,121 --> 02:26:24,051 now let's change silver to gold and the condition two points greater than 3000 6514 02:26:24,051 --> 02:26:24,061 condition two points greater than 3000 6515 02:26:24,061 --> 02:26:27,770 condition two points greater than 3000 and finally we do an order by let's run 6516 02:26:27,770 --> 02:26:27,780 and finally we do an order by let's run 6517 02:26:27,780 --> 02:26:30,831 and finally we do an order by let's run the query one more time and here's the 6518 02:26:30,831 --> 02:26:30,841 the query one more time and here's the 6519 02:26:30,841 --> 02:26:33,020 the query one more time and here's the end result our customers are sorted by 6520 02:26:33,020 --> 02:26:33,030 end result our customers are sorted by 6521 02:26:33,030 --> 02:26:35,031 end result our customers are sorted by their first name we see all the bronze 6522 02:26:35,031 --> 02:26:35,041 their first name we see all the bronze 6523 02:26:35,041 --> 02:26:42,151 their first name we see all the bronze silver and gold customers 6524 02:26:42,151 --> 02:26:42,161 6525 02:26:42,161 --> 02:26:44,470 in the section I'm gonna teach you how 6526 02:26:44,470 --> 02:26:44,480 in the section I'm gonna teach you how 6527 02:26:44,480 --> 02:26:47,711 in the section I'm gonna teach you how to insert update and delete data before 6528 02:26:47,711 --> 02:26:47,721 to insert update and delete data before 6529 02:26:47,721 --> 02:26:49,480 to insert update and delete data before we get started let's have a closer look 6530 02:26:49,480 --> 02:26:49,490 we get started let's have a closer look 6531 02:26:49,490 --> 02:26:52,301 we get started let's have a closer look at our customers table so click on this 6532 02:26:52,301 --> 02:26:52,311 at our customers table so click on this 6533 02:26:52,311 --> 02:26:54,341 at our customers table so click on this middle icon to open this table in the 6534 02:26:54,341 --> 02:26:54,351 middle icon to open this table in the 6535 02:26:54,351 --> 02:26:56,861 middle icon to open this table in the design mode what you see here might look 6536 02:26:56,861 --> 02:26:56,871 design mode what you see here might look 6537 02:26:56,871 --> 02:26:59,020 design mode what you see here might look a little bit intimidating at first but 6538 02:26:59,020 --> 02:26:59,030 a little bit intimidating at first but 6539 02:26:59,030 --> 02:27:01,270 a little bit intimidating at first but trust me this is actually so easy and in 6540 02:27:01,270 --> 02:27:01,280 trust me this is actually so easy and in 6541 02:27:01,280 --> 02:27:02,651 trust me this is actually so easy and in this tutorial I'm gonna explain exactly 6542 02:27:02,651 --> 02:27:02,661 this tutorial I'm gonna explain exactly 6543 02:27:02,661 --> 02:27:06,671 this tutorial I'm gonna explain exactly what we have in these columns so on the 6544 02:27:06,671 --> 02:27:06,681 what we have in these columns so on the 6545 02:27:06,681 --> 02:27:08,051 what we have in these columns so on the left side you can see the column name 6546 02:27:08,051 --> 02:27:08,061 left side you can see the column name 6547 02:27:08,061 --> 02:27:10,331 left side you can see the column name next to that you can see the data type 6548 02:27:10,331 --> 02:27:10,341 next to that you can see the data type 6549 02:27:10,341 --> 02:27:12,461 next to that you can see the data type for each column so our customer ID 6550 02:27:12,461 --> 02:27:12,471 for each column so our customer ID 6551 02:27:12,471 --> 02:27:14,951 for each column so our customer ID column can only accept integer values 6552 02:27:14,951 --> 02:27:14,961 column can only accept integer values 6553 02:27:14,961 --> 02:27:17,651 column can only accept integer values integers are whole numbers like 1 2 3 4 6554 02:27:17,651 --> 02:27:17,661 integers are whole numbers like 1 2 3 4 6555 02:27:17,661 --> 02:27:18,281 integers are whole numbers like 1 2 3 4 and so on 6556 02:27:18,281 --> 02:27:18,291 and so on 6557 02:27:18,291 --> 02:27:20,680 and so on they don't have decimal points first 6558 02:27:20,680 --> 02:27:20,690 they don't have decimal points first 6559 02:27:20,690 --> 02:27:23,140 they don't have decimal points first name is a VAR char which is short for 6560 02:27:23,140 --> 02:27:23,150 name is a VAR char which is short for 6561 02:27:23,150 --> 02:27:26,501 name is a VAR char which is short for variable character I hate in parentheses 6562 02:27:26,501 --> 02:27:26,511 variable character I hate in parentheses 6563 02:27:26,511 --> 02:27:28,961 variable character I hate in parentheses you can see 50 that basically means in 6564 02:27:28,961 --> 02:27:28,971 you can see 50 that basically means in 6565 02:27:28,971 --> 02:27:31,991 you can see 50 that basically means in this column we can have a maximum of 50 6566 02:27:31,991 --> 02:27:32,001 this column we can have a maximum of 50 6567 02:27:32,001 --> 02:27:34,270 this column we can have a maximum of 50 characters now if the name of a customer 6568 02:27:34,270 --> 02:27:34,280 characters now if the name of a customer 6569 02:27:34,280 --> 02:27:36,941 characters now if the name of a customer is only 5 characters long we only store 6570 02:27:36,941 --> 02:27:36,951 is only 5 characters long we only store 6571 02:27:36,951 --> 02:27:39,611 is only 5 characters long we only store those 5 characters so even though the 6572 02:27:39,611 --> 02:27:39,621 those 5 characters so even though the 6573 02:27:39,621 --> 02:27:42,131 those 5 characters so even though the maximum length for this column is 15 we 6574 02:27:42,131 --> 02:27:42,141 maximum length for this column is 15 we 6575 02:27:42,141 --> 02:27:43,781 maximum length for this column is 15 we are not gonna waste space if the 6576 02:27:43,781 --> 02:27:43,791 are not gonna waste space if the 6577 02:27:43,791 --> 02:27:45,551 are not gonna waste space if the customers name is less than 50 6578 02:27:45,551 --> 02:27:45,561 customers name is less than 50 6579 02:27:45,561 --> 02:27:48,491 customers name is less than 50 characters that is why here we have 4 6580 02:27:48,491 --> 02:27:48,501 characters that is why here we have 4 6581 02:27:48,501 --> 02:27:50,680 characters that is why here we have 4 char which is short for variable in 6582 02:27:50,680 --> 02:27:50,690 char which is short for variable in 6583 02:27:50,690 --> 02:27:52,720 char which is short for variable in contrast we have another data type that 6584 02:27:52,720 --> 02:27:52,730 contrast we have another data type that 6585 02:27:52,730 --> 02:27:56,171 contrast we have another data type that is character if you had character 50 6586 02:27:56,171 --> 02:27:56,181 is character if you had character 50 6587 02:27:56,181 --> 02:27:57,850 is character if you had character 50 here and the name of the customer was 6588 02:27:57,850 --> 02:27:57,860 here and the name of the customer was 6589 02:27:57,860 --> 02:28:00,131 here and the name of the customer was only 5 characters long my skill will 6590 02:28:00,131 --> 02:28:00,141 only 5 characters long my skill will 6591 02:28:00,141 --> 02:28:03,941 only 5 characters long my skill will insert additional 45 spaces to fill this 6592 02:28:03,941 --> 02:28:03,951 insert additional 45 spaces to fill this 6593 02:28:03,951 --> 02:28:07,571 insert additional 45 spaces to fill this column so this is a waste of space so as 6594 02:28:07,571 --> 02:28:07,581 column so this is a waste of space so as 6595 02:28:07,581 --> 02:28:09,730 column so this is a waste of space so as a best practice most of the time we use 6596 02:28:09,730 --> 02:28:09,740 a best practice most of the time we use 6597 02:28:09,740 --> 02:28:13,301 a best practice most of the time we use var char to store string or textual 6598 02:28:13,301 --> 02:28:13,311 var char to store string or textual 6599 02:28:13,311 --> 02:28:15,761 var char to store string or textual values now here on the right side we 6600 02:28:15,761 --> 02:28:15,771 values now here on the right side we 6601 02:28:15,771 --> 02:28:17,921 values now here on the right side we have this column PK which is short for 6602 02:28:17,921 --> 02:28:17,931 have this column PK which is short for 6603 02:28:17,931 --> 02:28:21,551 have this column PK which is short for primary key so customer ID is marked as 6604 02:28:21,551 --> 02:28:21,561 primary key so customer ID is marked as 6605 02:28:21,561 --> 02:28:23,531 primary key so customer ID is marked as the primary key and that is why we have 6606 02:28:23,531 --> 02:28:23,541 the primary key and that is why we have 6607 02:28:23,541 --> 02:28:25,841 the primary key and that is why we have this yellow key here so the value is in 6608 02:28:25,841 --> 02:28:25,851 this yellow key here so the value is in 6609 02:28:25,851 --> 02:28:27,461 this yellow key here so the value is in this column uniquely identify each 6610 02:28:27,461 --> 02:28:27,471 this column uniquely identify each 6611 02:28:27,471 --> 02:28:30,730 this column uniquely identify each customer next to that we have an N which 6612 02:28:30,730 --> 02:28:30,740 customer next to that we have an N which 6613 02:28:30,740 --> 02:28:33,100 customer next to that we have an N which is short for not null and that 6614 02:28:33,100 --> 02:28:33,110 is short for not null and that 6615 02:28:33,110 --> 02:28:35,051 is short for not null and that determines if this column can accept 6616 02:28:35,051 --> 02:28:35,061 determines if this column can accept 6617 02:28:35,061 --> 02:28:37,331 determines if this column can accept null values or not in this case 6618 02:28:37,331 --> 02:28:37,341 null values or not in this case 6619 02:28:37,341 --> 02:28:40,060 null values or not in this case every customer record must have the 6620 02:28:40,060 --> 02:28:40,070 every customer record must have the 6621 02:28:40,070 --> 02:28:43,480 every customer record must have the customer ID first name last name as well 6622 02:28:43,480 --> 02:28:43,490 customer ID first name last name as well 6623 02:28:43,490 --> 02:28:46,091 customer ID first name last name as well as these other attributes but birthdate 6624 02:28:46,091 --> 02:28:46,101 as these other attributes but birthdate 6625 02:28:46,101 --> 02:28:48,220 as these other attributes but birthdate and phone are optional so in these 6626 02:28:48,220 --> 02:28:48,230 and phone are optional so in these 6627 02:28:48,230 --> 02:28:50,770 and phone are optional so in these columns we can have null values now we 6628 02:28:50,770 --> 02:28:50,780 columns we can have null values now we 6629 02:28:50,780 --> 02:28:51,370 columns we can have null values now we have in 6630 02:28:51,370 --> 02:28:51,380 have in 6631 02:28:51,380 --> 02:28:53,380 have in the column here AI which is short for 6632 02:28:53,380 --> 02:28:53,390 the column here AI which is short for 6633 02:28:53,390 --> 02:28:54,580 the column here AI which is short for autoincrement 6634 02:28:54,580 --> 02:28:54,590 autoincrement 6635 02:28:54,590 --> 02:28:57,490 autoincrement and this is often used with primary key 6636 02:28:57,490 --> 02:28:57,500 and this is often used with primary key 6637 02:28:57,500 --> 02:28:59,830 and this is often used with primary key columns so every time we insert and you 6638 02:28:59,830 --> 02:28:59,840 columns so every time we insert and you 6639 02:28:59,840 --> 02:29:02,650 columns so every time we insert and you record in this table we let MySQL or our 6640 02:29:02,650 --> 02:29:02,660 record in this table we let MySQL or our 6641 02:29:02,660 --> 02:29:05,290 record in this table we let MySQL or our database engine insert a value in this 6642 02:29:05,290 --> 02:29:05,300 database engine insert a value in this 6643 02:29:05,300 --> 02:29:07,330 database engine insert a value in this column so essentially it gets the 6644 02:29:07,330 --> 02:29:07,340 column so essentially it gets the 6645 02:29:07,340 --> 02:29:09,760 column so essentially it gets the customer ID for the last row and it will 6646 02:29:09,760 --> 02:29:09,770 customer ID for the last row and it will 6647 02:29:09,770 --> 02:29:12,070 customer ID for the last row and it will increment it by one at a time we insert 6648 02:29:12,070 --> 02:29:12,080 increment it by one at a time we insert 6649 02:29:12,080 --> 02:29:14,500 increment it by one at a time we insert a new record so if you look at the data 6650 02:29:14,500 --> 02:29:14,510 a new record so if you look at the data 6651 02:29:14,510 --> 02:29:17,590 a new record so if you look at the data you can see that currently we have only 6652 02:29:17,590 --> 02:29:17,600 you can see that currently we have only 6653 02:29:17,600 --> 02:29:19,719 you can see that currently we have only ten customers here so if you had a new 6654 02:29:19,719 --> 02:29:19,729 ten customers here so if you had a new 6655 02:29:19,729 --> 02:29:20,530 ten customers here so if you had a new customer here 6656 02:29:20,530 --> 02:29:20,540 customer here 6657 02:29:20,540 --> 02:29:22,690 customer here MySQL will assign eleven to the new 6658 02:29:22,690 --> 02:29:22,700 MySQL will assign eleven to the new 6659 02:29:22,700 --> 02:29:26,679 MySQL will assign eleven to the new customer okay and finally here we have 6660 02:29:26,679 --> 02:29:26,689 customer okay and finally here we have 6661 02:29:26,689 --> 02:29:28,690 customer okay and finally here we have another column that specifies the 6662 02:29:28,690 --> 02:29:28,700 another column that specifies the 6663 02:29:28,700 --> 02:29:31,450 another column that specifies the default value for each column for 6664 02:29:31,450 --> 02:29:31,460 default value for each column for 6665 02:29:31,460 --> 02:29:33,400 default value for each column for example for our birthdate and phone 6666 02:29:33,400 --> 02:29:33,410 example for our birthdate and phone 6667 02:29:33,410 --> 02:29:36,730 example for our birthdate and phone columns that default values are not so 6668 02:29:36,730 --> 02:29:36,740 columns that default values are not so 6669 02:29:36,740 --> 02:29:39,040 columns that default values are not so if we don't supply a value my skill will 6670 02:29:39,040 --> 02:29:39,050 if we don't supply a value my skill will 6671 02:29:39,050 --> 02:29:41,130 if we don't supply a value my skill will use the null values for these columns 6672 02:29:41,130 --> 02:29:41,140 use the null values for these columns 6673 02:29:41,140 --> 02:29:43,900 use the null values for these columns similarly we have another default value 6674 02:29:43,900 --> 02:29:43,910 similarly we have another default value 6675 02:29:43,910 --> 02:29:45,820 similarly we have another default value for the points column so if you don't 6676 02:29:45,820 --> 02:29:45,830 for the points column so if you don't 6677 02:29:45,830 --> 02:29:47,770 for the points column so if you don't supply the points for a customer my 6678 02:29:47,770 --> 02:29:47,780 supply the points for a customer my 6679 02:29:47,780 --> 02:29:50,440 supply the points for a customer my skill will use zero now we have a few 6680 02:29:50,440 --> 02:29:50,450 skill will use zero now we have a few 6681 02:29:50,450 --> 02:29:51,850 skill will use zero now we have a few other columns here which are not 6682 02:29:51,850 --> 02:29:51,860 other columns here which are not 6683 02:29:51,860 --> 02:29:53,590 other columns here which are not important at this stage you will learn 6684 02:29:53,590 --> 02:29:53,600 important at this stage you will learn 6685 02:29:53,600 --> 02:29:55,840 important at this stage you will learn about them later in the course so now 6686 02:29:55,840 --> 02:29:55,850 about them later in the course so now 6687 02:29:55,850 --> 02:29:57,670 about them later in the course so now that you understand the attributes of 6688 02:29:57,670 --> 02:29:57,680 that you understand the attributes of 6689 02:29:57,680 --> 02:30:00,130 that you understand the attributes of each column in this table let's go ahead 6690 02:30:00,130 --> 02:30:00,140 each column in this table let's go ahead 6691 02:30:00,140 --> 02:30:07,011 each column in this table let's go ahead and insert data into this table 6692 02:30:07,011 --> 02:30:07,021 6693 02:30:07,021 --> 02:30:08,970 in this tutorial you're gonna learn how 6694 02:30:08,970 --> 02:30:08,980 in this tutorial you're gonna learn how 6695 02:30:08,980 --> 02:30:12,000 in this tutorial you're gonna learn how to insert a row into a table for that 6696 02:30:12,000 --> 02:30:12,010 to insert a row into a table for that 6697 02:30:12,010 --> 02:30:13,920 to insert a row into a table for that we're gonna use the insert into 6698 02:30:13,920 --> 02:30:13,930 we're gonna use the insert into 6699 02:30:13,930 --> 02:30:16,740 we're gonna use the insert into statement where are we going to insert 6700 02:30:16,740 --> 02:30:16,750 statement where are we going to insert 6701 02:30:16,750 --> 02:30:19,530 statement where are we going to insert this row into the customers table so we 6702 02:30:19,530 --> 02:30:19,540 this row into the customers table so we 6703 02:30:19,540 --> 02:30:21,440 this row into the customers table so we type out the name of the table here 6704 02:30:21,440 --> 02:30:21,450 type out the name of the table here 6705 02:30:21,450 --> 02:30:25,230 type out the name of the table here followed by the values clause and here 6706 02:30:25,230 --> 02:30:25,240 followed by the values clause and here 6707 02:30:25,240 --> 02:30:27,750 followed by the values clause and here in parentheses we supply the values for 6708 02:30:27,750 --> 02:30:27,760 in parentheses we supply the values for 6709 02:30:27,760 --> 02:30:30,660 in parentheses we supply the values for every column in this table so back to 6710 02:30:30,660 --> 02:30:30,670 every column in this table so back to 6711 02:30:30,670 --> 02:30:33,030 every column in this table so back to our table definition these are all the 6712 02:30:33,030 --> 02:30:33,040 our table definition these are all the 6713 02:30:33,040 --> 02:30:35,430 our table definition these are all the columns first we need to supply a value 6714 02:30:35,430 --> 02:30:35,440 columns first we need to supply a value 6715 02:30:35,440 --> 02:30:38,310 columns first we need to supply a value for the customer ID column however in 6716 02:30:38,310 --> 02:30:38,320 for the customer ID column however in 6717 02:30:38,320 --> 02:30:41,011 for the customer ID column however in this column the auto increment attribute 6718 02:30:41,011 --> 02:30:41,021 this column the auto increment attribute 6719 02:30:41,021 --> 02:30:43,200 this column the auto increment attribute is enabled and as I told you before if 6720 02:30:43,200 --> 02:30:43,210 is enabled and as I told you before if 6721 02:30:43,210 --> 02:30:45,750 is enabled and as I told you before if we don't supply a value my skill will 6722 02:30:45,750 --> 02:30:45,760 we don't supply a value my skill will 6723 02:30:45,760 --> 02:30:49,200 we don't supply a value my skill will generate a unique value for us so we can 6724 02:30:49,200 --> 02:30:49,210 generate a unique value for us so we can 6725 02:30:49,210 --> 02:30:50,850 generate a unique value for us so we can go back to our statement and either 6726 02:30:50,850 --> 02:30:50,860 go back to our statement and either 6727 02:30:50,860 --> 02:30:54,570 go back to our statement and either assign an explicit value or use default 6728 02:30:54,570 --> 02:30:54,580 assign an explicit value or use default 6729 02:30:54,580 --> 02:30:57,150 assign an explicit value or use default to let MySQL take care of generating 6730 02:30:57,150 --> 02:30:57,160 to let MySQL take care of generating 6731 02:30:57,160 --> 02:30:58,650 to let MySQL take care of generating this value this is the preferred 6732 02:30:58,650 --> 02:30:58,660 this value this is the preferred 6733 02:30:58,660 --> 02:31:00,990 this value this is the preferred approach because if you use an explicit 6734 02:31:00,990 --> 02:31:01,000 approach because if you use an explicit 6735 02:31:01,000 --> 02:31:03,420 approach because if you use an explicit value like 200 it is possible that you 6736 02:31:03,420 --> 02:31:03,430 value like 200 it is possible that you 6737 02:31:03,430 --> 02:31:05,160 value like 200 it is possible that you might have another customer with the 6738 02:31:05,160 --> 02:31:05,170 might have another customer with the 6739 02:31:05,170 --> 02:31:07,051 might have another customer with the same ID so when you execute this 6740 02:31:07,051 --> 02:31:07,061 same ID so when you execute this 6741 02:31:07,061 --> 02:31:08,220 same ID so when you execute this statement you're gonna get an error 6742 02:31:08,220 --> 02:31:08,230 statement you're gonna get an error 6743 02:31:08,230 --> 02:31:09,960 statement you're gonna get an error because you cannot have duplicate values 6744 02:31:09,960 --> 02:31:09,970 because you cannot have duplicate values 6745 02:31:09,970 --> 02:31:12,660 because you cannot have duplicate values in this column every value should be 6746 02:31:12,660 --> 02:31:12,670 in this column every value should be 6747 02:31:12,670 --> 02:31:14,551 in this column every value should be unique so here we're gonna use the 6748 02:31:14,551 --> 02:31:14,561 unique so here we're gonna use the 6749 02:31:14,561 --> 02:31:16,170 unique so here we're gonna use the default keyword to let my SKU I'll 6750 02:31:16,170 --> 02:31:16,180 default keyword to let my SKU I'll 6751 02:31:16,180 --> 02:31:18,540 default keyword to let my SKU I'll generate a unique value for the customer 6752 02:31:18,540 --> 02:31:18,550 generate a unique value for the customer 6753 02:31:18,550 --> 02:31:21,210 generate a unique value for the customer ID now after that we need to supply a 6754 02:31:21,210 --> 02:31:21,220 ID now after that we need to supply a 6755 02:31:21,220 --> 02:31:22,700 ID now after that we need to supply a value for the first-name and lastname 6756 02:31:22,700 --> 02:31:22,710 value for the first-name and lastname 6757 02:31:22,710 --> 02:31:28,090 value for the first-name and lastname columns so let's say John Smith 6758 02:31:28,090 --> 02:31:28,100 columns so let's say John Smith 6759 02:31:28,100 --> 02:31:30,070 columns so let's say John Smith note that I have enclosed these values 6760 02:31:30,070 --> 02:31:30,080 note that I have enclosed these values 6761 02:31:30,080 --> 02:31:32,080 note that I have enclosed these values with quotes because as I told you before 6762 02:31:32,080 --> 02:31:32,090 with quotes because as I told you before 6763 02:31:32,090 --> 02:31:34,511 with quotes because as I told you before in sequel we should always enclose 6764 02:31:34,511 --> 02:31:34,521 in sequel we should always enclose 6765 02:31:34,521 --> 02:31:37,120 in sequel we should always enclose string and date values with quotes 6766 02:31:37,120 --> 02:31:37,130 string and date values with quotes 6767 02:31:37,130 --> 02:31:40,840 string and date values with quotes either single or double quotes okay now 6768 02:31:40,840 --> 02:31:40,850 either single or double quotes okay now 6769 02:31:40,850 --> 02:31:44,130 either single or double quotes okay now what else back to our customers table 6770 02:31:44,130 --> 02:31:44,140 what else back to our customers table 6771 02:31:44,140 --> 02:31:46,930 what else back to our customers table after the last name we have the birth 6772 02:31:46,930 --> 02:31:46,940 after the last name we have the birth 6773 02:31:46,940 --> 02:31:49,420 after the last name we have the birth date however as you can see this column 6774 02:31:49,420 --> 02:31:49,430 date however as you can see this column 6775 02:31:49,430 --> 02:31:51,340 date however as you can see this column is optional because this check box is 6776 02:31:51,340 --> 02:31:51,350 is optional because this check box is 6777 02:31:51,350 --> 02:31:53,770 is optional because this check box is not checked so here we can use null or 6778 02:31:53,770 --> 02:31:53,780 not checked so here we can use null or 6779 02:31:53,780 --> 02:31:56,470 not checked so here we can use null or an explicit value null means the absence 6780 02:31:56,470 --> 02:31:56,480 an explicit value null means the absence 6781 02:31:56,480 --> 02:31:59,680 an explicit value null means the absence of a value so back to our statement we 6782 02:31:59,680 --> 02:31:59,690 of a value so back to our statement we 6783 02:31:59,690 --> 02:32:01,930 of a value so back to our statement we can type out a birth date like 1990 6784 02:32:01,930 --> 02:32:01,940 can type out a birth date like 1990 6785 02:32:01,940 --> 02:32:06,220 can type out a birth date like 1990 January 1st or we could use the null 6786 02:32:06,220 --> 02:32:06,230 January 1st or we could use the null 6787 02:32:06,230 --> 02:32:08,890 January 1st or we could use the null keyword to leave out this value in this 6788 02:32:08,890 --> 02:32:08,900 keyword to leave out this value in this 6789 02:32:08,900 --> 02:32:12,280 keyword to leave out this value in this demo I'm gonna use a valid date now to 6790 02:32:12,280 --> 02:32:12,290 demo I'm gonna use a valid date now to 6791 02:32:12,290 --> 02:32:13,960 demo I'm gonna use a valid date now to make this code cleaner and more readable 6792 02:32:13,960 --> 02:32:13,970 make this code cleaner and more readable 6793 02:32:13,970 --> 02:32:16,060 make this code cleaner and more readable I'm gonna break it up into multiple 6794 02:32:16,060 --> 02:32:16,070 I'm gonna break it up into multiple 6795 02:32:16,070 --> 02:32:20,650 I'm gonna break it up into multiple lines that's better now back to our 6796 02:32:20,650 --> 02:32:20,660 lines that's better now back to our 6797 02:32:20,660 --> 02:32:24,280 lines that's better now back to our table next we have phone and phone is 6798 02:32:24,280 --> 02:32:24,290 table next we have phone and phone is 6799 02:32:24,290 --> 02:32:26,680 table next we have phone and phone is also optional because this check box is 6800 02:32:26,680 --> 02:32:26,690 also optional because this check box is 6801 02:32:26,690 --> 02:32:29,050 also optional because this check box is not checked and known is the default 6802 02:32:29,050 --> 02:32:29,060 not checked and known is the default 6803 02:32:29,060 --> 02:32:31,360 not checked and known is the default value for this caller so here we can 6804 02:32:31,360 --> 02:32:31,370 value for this caller so here we can 6805 02:32:31,370 --> 02:32:34,060 value for this caller so here we can explicitly pass null or use the default 6806 02:32:34,060 --> 02:32:34,070 explicitly pass null or use the default 6807 02:32:34,070 --> 02:32:36,761 explicitly pass null or use the default keyword and let MySQL put null into this 6808 02:32:36,761 --> 02:32:36,771 keyword and let MySQL put null into this 6809 02:32:36,771 --> 02:32:40,210 keyword and let MySQL put null into this column it's exactly the same so back to 6810 02:32:40,210 --> 02:32:40,220 column it's exactly the same so back to 6811 02:32:40,220 --> 02:32:42,450 column it's exactly the same so back to our statement we can pass null or 6812 02:32:42,450 --> 02:32:42,460 our statement we can pass null or 6813 02:32:42,460 --> 02:32:45,340 our statement we can pass null or default both these key words will have 6814 02:32:45,340 --> 02:32:45,350 default both these key words will have 6815 02:32:45,350 --> 02:32:47,710 default both these key words will have the same result in this case I'm gonna 6816 02:32:47,710 --> 02:32:47,720 the same result in this case I'm gonna 6817 02:32:47,720 --> 02:32:51,070 the same result in this case I'm gonna use the null keyword all right let's 6818 02:32:51,070 --> 02:32:51,080 use the null keyword all right let's 6819 02:32:51,080 --> 02:32:53,740 use the null keyword all right let's have one more look at our table next we 6820 02:32:53,740 --> 02:32:53,750 have one more look at our table next we 6821 02:32:53,750 --> 02:32:57,280 have one more look at our table next we have 4 more columns that are required to 6822 02:32:57,280 --> 02:32:57,290 have 4 more columns that are required to 6823 02:32:57,290 --> 02:33:00,190 have 4 more columns that are required to address city state and points I note 6824 02:33:00,190 --> 02:33:00,200 address city state and points I note 6825 02:33:00,200 --> 02:33:02,590 address city state and points I note that point has the default value of 0 so 6826 02:33:02,590 --> 02:33:02,600 that point has the default value of 0 so 6827 02:33:02,600 --> 02:33:04,511 that point has the default value of 0 so we can either use an explicit value like 6828 02:33:04,511 --> 02:33:04,521 we can either use an explicit value like 6829 02:33:04,521 --> 02:33:07,180 we can either use an explicit value like 200 or use the default keyboard and let 6830 02:33:07,180 --> 02:33:07,190 200 or use the default keyboard and let 6831 02:33:07,190 --> 02:33:11,320 200 or use the default keyboard and let MySQL generate 0 so back to our 6832 02:33:11,320 --> 02:33:11,330 MySQL generate 0 so back to our 6833 02:33:11,330 --> 02:33:14,620 MySQL generate 0 so back to our statement let's type out an address it 6834 02:33:14,620 --> 02:33:14,630 statement let's type out an address it 6835 02:33:14,630 --> 02:33:15,490 statement let's type out an address it doesn't really matter 6836 02:33:15,490 --> 02:33:15,500 doesn't really matter 6837 02:33:15,500 --> 02:33:19,210 doesn't really matter followed by a city and a state let's say 6838 02:33:19,210 --> 02:33:19,220 followed by a city and a state let's say 6839 02:33:19,220 --> 02:33:22,930 followed by a city and a state let's say California and finally points again we 6840 02:33:22,930 --> 02:33:22,940 California and finally points again we 6841 02:33:22,940 --> 02:33:27,100 California and finally points again we can use an explicit value or default so 6842 02:33:27,100 --> 02:33:27,110 can use an explicit value or default so 6843 02:33:27,110 --> 02:33:28,870 can use an explicit value or default so this is how we can insert a row into a 6844 02:33:28,870 --> 02:33:28,880 this is how we can insert a row into a 6845 02:33:28,880 --> 02:33:31,900 this is how we can insert a row into a table however in this example we're only 6846 02:33:31,900 --> 02:33:31,910 table however in this example we're only 6847 02:33:31,910 --> 02:33:34,390 table however in this example we're only supplying values for first name last 6848 02:33:34,390 --> 02:33:34,400 supplying values for first name last 6849 02:33:34,400 --> 02:33:38,530 supplying values for first name last name birth date and is address fields so 6850 02:33:38,530 --> 02:33:38,540 name birth date and is address fields so 6851 02:33:38,540 --> 02:33:40,511 name birth date and is address fields so we're living out the phone number the 6852 02:33:40,511 --> 02:33:40,521 we're living out the phone number the 6853 02:33:40,521 --> 02:33:41,950 we're living out the phone number the customer ID and 6854 02:33:41,950 --> 02:33:41,960 customer ID and 6855 02:33:41,960 --> 02:33:43,990 customer ID and the points so there's another way to 6856 02:33:43,990 --> 02:33:44,000 the points so there's another way to 6857 02:33:44,000 --> 02:33:45,480 the points so there's another way to write this statement and we'll show you 6858 02:33:45,480 --> 02:33:45,490 write this statement and we'll show you 6859 02:33:45,490 --> 02:33:48,580 write this statement and we'll show you so after the table name we can 6860 02:33:48,580 --> 02:33:48,590 so after the table name we can 6861 02:33:48,590 --> 02:33:51,610 so after the table name we can optionally supply the list of columns 6862 02:33:51,610 --> 02:33:51,620 optionally supply the list of columns 6863 02:33:51,620 --> 02:33:53,860 optionally supply the list of columns that you want to insert values into in 6864 02:33:53,860 --> 02:33:53,870 that you want to insert values into in 6865 02:33:53,870 --> 02:33:59,430 that you want to insert values into in this case first name last name birthdate 6866 02:33:59,430 --> 02:33:59,440 this case first name last name birthdate 6867 02:33:59,440 --> 02:34:01,630 this case first name last name birthdate now once again I'm gonna break up the 6868 02:34:01,630 --> 02:34:01,640 now once again I'm gonna break up the 6869 02:34:01,640 --> 02:34:07,390 now once again I'm gonna break up the statement into multiple lines so three 6870 02:34:07,390 --> 02:34:07,400 statement into multiple lines so three 6871 02:34:07,400 --> 02:34:13,540 statement into multiple lines so three more columns address city and state so 6872 02:34:13,540 --> 02:34:13,550 more columns address city and state so 6873 02:34:13,550 --> 02:34:15,340 more columns address city and state so these are the six columns that we're 6874 02:34:15,340 --> 02:34:15,350 these are the six columns that we're 6875 02:34:15,350 --> 02:34:17,950 these are the six columns that we're going to supply values for with this 6876 02:34:17,950 --> 02:34:17,960 going to supply values for with this 6877 02:34:17,960 --> 02:34:19,930 going to supply values for with this change we don't have to use is default 6878 02:34:19,930 --> 02:34:19,940 change we don't have to use is default 6879 02:34:19,940 --> 02:34:23,290 change we don't have to use is default or null values we only supply values for 6880 02:34:23,290 --> 02:34:23,300 or null values we only supply values for 6881 02:34:23,300 --> 02:34:24,700 or null values we only supply values for these columns so I'm going to remove 6882 02:34:24,700 --> 02:34:24,710 these columns so I'm going to remove 6883 02:34:24,710 --> 02:34:28,390 these columns so I'm going to remove default from here then no and finally 6884 02:34:28,390 --> 02:34:28,400 default from here then no and finally 6885 02:34:28,400 --> 02:34:32,460 default from here then no and finally this last default keyword 6886 02:34:32,460 --> 02:34:32,470 6887 02:34:32,470 --> 02:34:35,040 so this six values that we supplied here 6888 02:34:35,040 --> 02:34:35,050 so this six values that we supplied here 6889 02:34:35,050 --> 02:34:37,920 so this six values that we supplied here are used for this six column now with 6890 02:34:37,920 --> 02:34:37,930 are used for this six column now with 6891 02:34:37,930 --> 02:34:39,750 are used for this six column now with this change we can also reorder the 6892 02:34:39,750 --> 02:34:39,760 this change we can also reorder the 6893 02:34:39,760 --> 02:34:41,609 this change we can also reorder the columns we don't have to list them in 6894 02:34:41,609 --> 02:34:41,619 columns we don't have to list them in 6895 02:34:41,619 --> 02:34:43,830 columns we don't have to list them in the same order that they are defined in 6896 02:34:43,830 --> 02:34:43,840 the same order that they are defined in 6897 02:34:43,840 --> 02:34:47,279 the same order that they are defined in the customers table for example we can 6898 02:34:47,279 --> 02:34:47,289 the customers table for example we can 6899 02:34:47,289 --> 02:34:49,559 the customers table for example we can put the last name first and then 6900 02:34:49,559 --> 02:34:49,569 put the last name first and then 6901 02:34:49,569 --> 02:34:51,840 put the last name first and then obviously we should also swap the order 6902 02:34:51,840 --> 02:34:51,850 obviously we should also swap the order 6903 02:34:51,850 --> 02:34:53,849 obviously we should also swap the order of these values so we can list them in 6904 02:34:53,849 --> 02:34:53,859 of these values so we can list them in 6905 02:34:53,859 --> 02:34:56,160 of these values so we can list them in any orders now let's execute the 6906 02:34:56,160 --> 02:34:56,170 any orders now let's execute the 6907 02:34:56,170 --> 02:34:58,889 any orders now let's execute the statement now if you look at the output 6908 02:34:58,889 --> 02:34:58,899 statement now if you look at the output 6909 02:34:58,899 --> 02:35:01,410 statement now if you look at the output window down the bottom you should see 6910 02:35:01,410 --> 02:35:01,420 window down the bottom you should see 6911 02:35:01,420 --> 02:35:03,359 window down the bottom you should see the statement followed by one rows 6912 02:35:03,359 --> 02:35:03,369 the statement followed by one rows 6913 02:35:03,369 --> 02:35:06,000 the statement followed by one rows effective unfortunately I cannot resize 6914 02:35:06,000 --> 02:35:06,010 effective unfortunately I cannot resize 6915 02:35:06,010 --> 02:35:08,160 effective unfortunately I cannot resize this window to show you this message but 6916 02:35:08,160 --> 02:35:08,170 this window to show you this message but 6917 02:35:08,170 --> 02:35:09,660 this window to show you this message but if you look down below you can see that 6918 02:35:09,660 --> 02:35:09,670 if you look down below you can see that 6919 02:35:09,670 --> 02:35:11,849 if you look down below you can see that one record was affected which basically 6920 02:35:11,849 --> 02:35:11,859 one record was affected which basically 6921 02:35:11,859 --> 02:35:14,550 one record was affected which basically means one record was inserted into this 6922 02:35:14,550 --> 02:35:14,560 means one record was inserted into this 6923 02:35:14,560 --> 02:35:17,670 means one record was inserted into this table now let's look at the data in the 6924 02:35:17,670 --> 02:35:17,680 table now let's look at the data in the 6925 02:35:17,680 --> 02:35:22,139 table now let's look at the data in the customers table so the last row is the 6926 02:35:22,139 --> 02:35:22,149 customers table so the last row is the 6927 02:35:22,149 --> 02:35:24,599 customers table so the last row is the one that we inserted you can see that my 6928 02:35:24,599 --> 02:35:24,609 one that we inserted you can see that my 6929 02:35:24,609 --> 02:35:26,399 one that we inserted you can see that my skill automatically generated the value 6930 02:35:26,399 --> 02:35:26,409 skill automatically generated the value 6931 02:35:26,409 --> 02:35:28,800 skill automatically generated the value 11 this is the effect of auto increment 6932 02:35:28,800 --> 02:35:28,810 11 this is the effect of auto increment 6933 02:35:28,810 --> 02:35:31,139 11 this is the effect of auto increment attribute so it takes the value of the 6934 02:35:31,139 --> 02:35:31,149 attribute so it takes the value of the 6935 02:35:31,149 --> 02:35:34,139 attribute so it takes the value of the last row and increments it by one so 6936 02:35:34,139 --> 02:35:34,149 last row and increments it by one so 6937 02:35:34,149 --> 02:35:35,670 last row and increments it by one so here we have the first name last name 6938 02:35:35,670 --> 02:35:35,680 here we have the first name last name 6939 02:35:35,680 --> 02:35:38,399 here we have the first name last name the birthday we didn't supply a value 6940 02:35:38,399 --> 02:35:38,409 the birthday we didn't supply a value 6941 02:35:38,409 --> 02:35:40,590 the birthday we didn't supply a value for a phone attribute so that's why we 6942 02:35:40,590 --> 02:35:40,600 for a phone attribute so that's why we 6943 02:35:40,600 --> 02:35:44,250 for a phone attribute so that's why we have null here we also have address city 6944 02:35:44,250 --> 02:35:44,260 have null here we also have address city 6945 02:35:44,260 --> 02:35:47,849 have null here we also have address city state and the default value of zero for 6946 02:35:47,849 --> 02:35:47,859 state and the default value of zero for 6947 02:35:47,859 --> 02:35:53,450 state and the default value of zero for the points 6948 02:35:53,450 --> 02:35:53,460 6949 02:35:53,460 --> 02:35:55,500 in this tutorial you're gonna learn how 6950 02:35:55,500 --> 02:35:55,510 in this tutorial you're gonna learn how 6951 02:35:55,510 --> 02:35:58,350 in this tutorial you're gonna learn how to insert multiple rows in one go for 6952 02:35:58,350 --> 02:35:58,360 to insert multiple rows in one go for 6953 02:35:58,360 --> 02:35:59,970 to insert multiple rows in one go for this demo we're gonna use this shippers 6954 02:35:59,970 --> 02:35:59,980 this demo we're gonna use this shippers 6955 02:35:59,980 --> 02:36:02,310 this demo we're gonna use this shippers table let's have a quick look at the 6956 02:36:02,310 --> 02:36:02,320 table let's have a quick look at the 6957 02:36:02,320 --> 02:36:04,860 table let's have a quick look at the table definition so here we have two 6958 02:36:04,860 --> 02:36:04,870 table definition so here we have two 6959 02:36:04,870 --> 02:36:07,830 table definition so here we have two columns shipper ID a name shipper ID is 6960 02:36:07,830 --> 02:36:07,840 columns shipper ID a name shipper ID is 6961 02:36:07,840 --> 02:36:10,920 columns shipper ID a name shipper ID is a primary key it's not nullable and it's 6962 02:36:10,920 --> 02:36:10,930 a primary key it's not nullable and it's 6963 02:36:10,930 --> 02:36:13,051 a primary key it's not nullable and it's an auto incremented column so we're 6964 02:36:13,051 --> 02:36:13,061 an auto incremented column so we're 6965 02:36:13,061 --> 02:36:15,120 an auto incremented column so we're gonna let MySQL generate values for this 6966 02:36:15,120 --> 02:36:15,130 gonna let MySQL generate values for this 6967 02:36:15,130 --> 02:36:17,730 gonna let MySQL generate values for this column easy we only need to supply a 6968 02:36:17,730 --> 02:36:17,740 column easy we only need to supply a 6969 02:36:17,740 --> 02:36:20,280 column easy we only need to supply a value for the name color soap actor Cory 6970 02:36:20,280 --> 02:36:20,290 value for the name color soap actor Cory 6971 02:36:20,290 --> 02:36:24,410 value for the name color soap actor Cory editor window we type out insert into 6972 02:36:24,410 --> 02:36:24,420 editor window we type out insert into 6973 02:36:24,420 --> 02:36:28,020 editor window we type out insert into shippers in parentheses we specify the 6974 02:36:28,020 --> 02:36:28,030 shippers in parentheses we specify the 6975 02:36:28,030 --> 02:36:29,460 shippers in parentheses we specify the name of the columns we want to insert 6976 02:36:29,460 --> 02:36:29,470 name of the columns we want to insert 6977 02:36:29,470 --> 02:36:33,030 name of the columns we want to insert values into in this case name followed 6978 02:36:33,030 --> 02:36:33,040 values into in this case name followed 6979 02:36:33,040 --> 02:36:35,761 values into in this case name followed by the values clause here we add a pair 6980 02:36:35,761 --> 02:36:35,771 by the values clause here we add a pair 6981 02:36:35,771 --> 02:36:38,190 by the values clause here we add a pair of parentheses with a value like shipper 6982 02:36:38,190 --> 02:36:38,200 of parentheses with a value like shipper 6983 02:36:38,200 --> 02:36:41,790 of parentheses with a value like shipper 1 now to insert multiple rows all you 6984 02:36:41,790 --> 02:36:41,800 1 now to insert multiple rows all you 6985 02:36:41,800 --> 02:36:44,540 1 now to insert multiple rows all you have to do is to add a comma followed by 6986 02:36:44,540 --> 02:36:44,550 have to do is to add a comma followed by 6987 02:36:44,550 --> 02:36:47,640 have to do is to add a comma followed by another pair of parentheses so cheaper 6988 02:36:47,640 --> 02:36:47,650 another pair of parentheses so cheaper 6989 02:36:47,650 --> 02:36:50,820 another pair of parentheses so cheaper too and one more time comma parentheses 6990 02:36:50,820 --> 02:36:50,830 too and one more time comma parentheses 6991 02:36:50,830 --> 02:36:54,060 too and one more time comma parentheses shipper 3 this is how you can insert 6992 02:36:54,060 --> 02:36:54,070 shipper 3 this is how you can insert 6993 02:36:54,070 --> 02:36:56,910 shipper 3 this is how you can insert multiple rows in one go now let's 6994 02:36:56,910 --> 02:36:56,920 multiple rows in one go now let's 6995 02:36:56,920 --> 02:37:00,750 multiple rows in one go now let's execute this statement alright and then 6996 02:37:00,750 --> 02:37:00,760 execute this statement alright and then 6997 02:37:00,760 --> 02:37:04,640 execute this statement alright and then inspect the data in the shippers table 6998 02:37:04,640 --> 02:37:04,650 inspect the data in the shippers table 6999 02:37:04,650 --> 02:37:07,980 inspect the data in the shippers table there you go so initially we had only 7000 02:37:07,980 --> 02:37:07,990 there you go so initially we had only 7001 02:37:07,990 --> 02:37:10,140 there you go so initially we had only five shippers and here are the three new 7002 02:37:10,140 --> 02:37:10,150 five shippers and here are the three new 7003 02:37:10,150 --> 02:37:12,390 five shippers and here are the three new shippers that we inserted note that my 7004 02:37:12,390 --> 02:37:12,400 shippers that we inserted note that my 7005 02:37:12,400 --> 02:37:14,551 shippers that we inserted note that my SKU automatically generated the values 7006 02:37:14,551 --> 02:37:14,561 SKU automatically generated the values 7007 02:37:14,561 --> 02:37:17,220 SKU automatically generated the values for the shipper ID column so we have 6 7 7008 02:37:17,220 --> 02:37:17,230 for the shipper ID column so we have 6 7 7009 02:37:17,230 --> 02:37:22,349 for the shipper ID column so we have 6 7 & 8 7010 02:37:22,349 --> 02:37:22,359 7011 02:37:22,359 --> 02:37:24,609 all right here's your exercise for this 7012 02:37:24,609 --> 02:37:24,619 all right here's your exercise for this 7013 02:37:24,619 --> 02:37:27,130 all right here's your exercise for this tutorial write a statement to insert 7014 02:37:27,130 --> 02:37:27,140 tutorial write a statement to insert 7015 02:37:27,140 --> 02:37:30,099 tutorial write a statement to insert three rows in the products table that's 7016 02:37:30,099 --> 02:37:30,109 three rows in the products table that's 7017 02:37:30,109 --> 02:37:31,659 three rows in the products table that's pretty easy you can knock it out in a 7018 02:37:31,659 --> 02:37:31,669 pretty easy you can knock it out in a 7019 02:37:31,669 --> 02:37:33,300 pretty easy you can knock it out in a minute 7020 02:37:33,300 --> 02:37:33,310 minute 7021 02:37:33,310 --> 02:37:36,519 minute you 7022 02:37:36,519 --> 02:37:36,529 7023 02:37:36,529 --> 02:37:39,349 so here's our products table we only 7024 02:37:39,349 --> 02:37:39,359 so here's our products table we only 7025 02:37:39,359 --> 02:37:41,420 so here's our products table we only have four columns we're gonna leave out 7026 02:37:41,420 --> 02:37:41,430 have four columns we're gonna leave out 7027 02:37:41,430 --> 02:37:43,069 have four columns we're gonna leave out the first column because it's an auto 7028 02:37:43,069 --> 02:37:43,079 the first column because it's an auto 7029 02:37:43,079 --> 02:37:45,080 the first column because it's an auto incremented column so we only have to 7030 02:37:45,080 --> 02:37:45,090 incremented column so we only have to 7031 02:37:45,090 --> 02:37:47,899 incremented column so we only have to supply values for name quantity and unit 7032 02:37:47,899 --> 02:37:47,909 supply values for name quantity and unit 7033 02:37:47,909 --> 02:37:50,649 supply values for name quantity and unit price back to our query editor window 7034 02:37:50,649 --> 02:37:50,659 price back to our query editor window 7035 02:37:50,659 --> 02:37:55,309 price back to our query editor window let's insert into product the columns 7036 02:37:55,309 --> 02:37:55,319 let's insert into product the columns 7037 02:37:55,319 --> 02:38:00,139 let's insert into product the columns are named quantity in stock and unit 7038 02:38:00,139 --> 02:38:00,149 are named quantity in stock and unit 7039 02:38:00,149 --> 02:38:03,679 are named quantity in stock and unit price and the values are gonna be let's 7040 02:38:03,679 --> 02:38:03,689 price and the values are gonna be let's 7041 02:38:03,689 --> 02:38:06,679 price and the values are gonna be let's say product one stock is gonna be ten 7042 02:38:06,679 --> 02:38:06,689 say product one stock is gonna be ten 7043 02:38:06,689 --> 02:38:08,840 say product one stock is gonna be ten and the unit price is gonna be one point 7044 02:38:08,840 --> 02:38:08,850 and the unit price is gonna be one point 7045 02:38:08,850 --> 02:38:11,090 and the unit price is gonna be one point ninety five now I'm gonna select these 7046 02:38:11,090 --> 02:38:11,100 ninety five now I'm gonna select these 7047 02:38:11,100 --> 02:38:16,540 ninety five now I'm gonna select these values copy come up paste it like this 7048 02:38:16,540 --> 02:38:16,550 values copy come up paste it like this 7049 02:38:16,550 --> 02:38:19,779 values copy come up paste it like this change the values accordingly and 7050 02:38:19,779 --> 02:38:19,789 change the values accordingly and 7051 02:38:19,789 --> 02:38:24,590 change the values accordingly and finally the last row product three there 7052 02:38:24,590 --> 02:38:24,600 finally the last row product three there 7053 02:38:24,600 --> 02:38:28,159 finally the last row product three there you go let's execute the statement all 7054 02:38:28,159 --> 02:38:28,169 you go let's execute the statement all 7055 02:38:28,169 --> 02:38:32,000 you go let's execute the statement all right and then verify the result so in 7056 02:38:32,000 --> 02:38:32,010 right and then verify the result so in 7057 02:38:32,010 --> 02:38:34,300 right and then verify the result so in the products table now we should have 7058 02:38:34,300 --> 02:38:34,310 the products table now we should have 7059 02:38:34,310 --> 02:38:37,370 the products table now we should have three new records now the ideas you see 7060 02:38:37,370 --> 02:38:37,380 three new records now the ideas you see 7061 02:38:37,380 --> 02:38:39,679 three new records now the ideas you see here are 15 16 and 17 7062 02:38:39,679 --> 02:38:39,689 here are 15 16 and 17 7063 02:38:39,689 --> 02:38:41,599 here are 15 16 and 17 because before recording this video I 7064 02:38:41,599 --> 02:38:41,609 because before recording this video I 7065 02:38:41,609 --> 02:38:43,939 because before recording this video I actually inserted a few records in this 7066 02:38:43,939 --> 02:38:43,949 actually inserted a few records in this 7067 02:38:43,949 --> 02:38:44,330 actually inserted a few records in this table 7068 02:38:44,330 --> 02:38:44,340 table 7069 02:38:44,340 --> 02:38:46,729 table and then deleted them so I had product 7070 02:38:46,729 --> 02:38:46,739 and then deleted them so I had product 7071 02:38:46,739 --> 02:38:49,849 and then deleted them so I had product IDs 11 12 13 and 14 7072 02:38:49,849 --> 02:38:49,859 IDs 11 12 13 and 14 7073 02:38:49,859 --> 02:38:51,769 IDs 11 12 13 and 14 now even though they're actually deleted 7074 02:38:51,769 --> 02:38:51,779 now even though they're actually deleted 7075 02:38:51,779 --> 02:38:53,779 now even though they're actually deleted from this table my skilled remembers 7076 02:38:53,779 --> 02:38:53,789 from this table my skilled remembers 7077 02:38:53,789 --> 02:38:56,540 from this table my skilled remembers their IDs so instead of incrementing 10 7078 02:38:56,540 --> 02:38:56,550 their IDs so instead of incrementing 10 7079 02:38:56,550 --> 02:38:59,510 their IDs so instead of incrementing 10 by 11 it incremented 14 which was the 7080 02:38:59,510 --> 02:38:59,520 by 11 it incremented 14 which was the 7081 02:38:59,520 --> 02:39:01,670 by 11 it incremented 14 which was the last record from before and that's why I 7082 02:39:01,670 --> 02:39:01,680 last record from before and that's why I 7083 02:39:01,680 --> 02:39:04,639 last record from before and that's why I generated 15 on your computer the IDS 7084 02:39:04,639 --> 02:39:04,649 generated 15 on your computer the IDS 7085 02:39:04,649 --> 02:39:11,801 generated 15 on your computer the IDS are going to be 11 12 and 13 7086 02:39:11,801 --> 02:39:11,811 7087 02:39:11,811 --> 02:39:14,030 so far you have only learned how to 7088 02:39:14,030 --> 02:39:14,040 so far you have only learned how to 7089 02:39:14,040 --> 02:39:16,940 so far you have only learned how to insert data into a single table in this 7090 02:39:16,940 --> 02:39:16,950 insert data into a single table in this 7091 02:39:16,950 --> 02:39:18,080 insert data into a single table in this tutorial I'm going to show you how to 7092 02:39:18,080 --> 02:39:18,090 tutorial I'm going to show you how to 7093 02:39:18,090 --> 02:39:20,690 tutorial I'm going to show you how to insert data into multiple tables here's 7094 02:39:20,690 --> 02:39:20,700 insert data into multiple tables here's 7095 02:39:20,700 --> 02:39:23,091 insert data into multiple tables here's a really good example look at the orders 7096 02:39:23,091 --> 02:39:23,101 a really good example look at the orders 7097 02:39:23,101 --> 02:39:26,060 a really good example look at the orders table what columns do we have here we 7098 02:39:26,060 --> 02:39:26,070 table what columns do we have here we 7099 02:39:26,070 --> 02:39:28,251 table what columns do we have here we have the order ID we have the customer 7100 02:39:28,251 --> 02:39:28,261 have the order ID we have the customer 7101 02:39:28,261 --> 02:39:30,350 have the order ID we have the customer ID so we know who has placed this order 7102 02:39:30,350 --> 02:39:30,360 ID so we know who has placed this order 7103 02:39:30,360 --> 02:39:32,990 ID so we know who has placed this order we know the date of the order we know 7104 02:39:32,990 --> 02:39:33,000 we know the date of the order we know 7105 02:39:33,000 --> 02:39:35,631 we know the date of the order we know the status comments as well as shipping 7106 02:39:35,631 --> 02:39:35,641 the status comments as well as shipping 7107 02:39:35,641 --> 02:39:38,211 the status comments as well as shipping information but the actual items for 7108 02:39:38,211 --> 02:39:38,221 information but the actual items for 7109 02:39:38,221 --> 02:39:40,580 information but the actual items for this order are not in this table they 7110 02:39:40,580 --> 02:39:40,590 this order are not in this table they 7111 02:39:40,590 --> 02:39:43,580 this order are not in this table they are in the order items table so in this 7112 02:39:43,580 --> 02:39:43,590 are in the order items table so in this 7113 02:39:43,590 --> 02:39:46,131 are in the order items table so in this table we have four columns we have the 7114 02:39:46,131 --> 02:39:46,141 table we have four columns we have the 7115 02:39:46,141 --> 02:39:48,801 table we have four columns we have the order ID so we know what order this item 7116 02:39:48,801 --> 02:39:48,811 order ID so we know what order this item 7117 02:39:48,811 --> 02:39:51,261 order ID so we know what order this item is for we have the product ID so we know 7118 02:39:51,261 --> 02:39:51,271 is for we have the product ID so we know 7119 02:39:51,271 --> 02:39:53,421 is for we have the product ID so we know what product has been ordered at what 7120 02:39:53,421 --> 02:39:53,431 what product has been ordered at what 7121 02:39:53,431 --> 02:39:56,810 what product has been ordered at what quantity and what price so an actual 7122 02:39:56,810 --> 02:39:56,820 quantity and what price so an actual 7123 02:39:56,820 --> 02:40:00,080 quantity and what price so an actual order can have one or more order items 7124 02:40:00,080 --> 02:40:00,090 order can have one or more order items 7125 02:40:00,090 --> 02:40:02,301 order can have one or more order items this is what we call a parent-child 7126 02:40:02,301 --> 02:40:02,311 this is what we call a parent-child 7127 02:40:02,311 --> 02:40:04,490 this is what we call a parent-child relationship so in this relationship the 7128 02:40:04,490 --> 02:40:04,500 relationship so in this relationship the 7129 02:40:04,500 --> 02:40:07,520 relationship so in this relationship the orders table is the parent and the order 7130 02:40:07,520 --> 02:40:07,530 orders table is the parent and the order 7131 02:40:07,530 --> 02:40:10,190 orders table is the parent and the order items table is a child so one row in the 7132 02:40:10,190 --> 02:40:10,200 items table is a child so one row in the 7133 02:40:10,200 --> 02:40:12,350 items table is a child so one row in the orders table can have one or more 7134 02:40:12,350 --> 02:40:12,360 orders table can have one or more 7135 02:40:12,360 --> 02:40:14,780 orders table can have one or more children inside the order items table 7136 02:40:14,780 --> 02:40:14,790 children inside the order items table 7137 02:40:14,790 --> 02:40:16,370 children inside the order items table now in this tutorial I'm going to show 7138 02:40:16,370 --> 02:40:16,380 now in this tutorial I'm going to show 7139 02:40:16,380 --> 02:40:19,040 now in this tutorial I'm going to show you how to insert an order and all its 7140 02:40:19,040 --> 02:40:19,050 you how to insert an order and all its 7141 02:40:19,050 --> 02:40:21,051 you how to insert an order and all its items so you will learn how to insert 7142 02:40:21,051 --> 02:40:21,061 items so you will learn how to insert 7143 02:40:21,061 --> 02:40:24,230 items so you will learn how to insert data into multiple tables alright back 7144 02:40:24,230 --> 02:40:24,240 data into multiple tables alright back 7145 02:40:24,240 --> 02:40:25,850 data into multiple tables alright back to our query editor window 7146 02:40:25,850 --> 02:40:25,860 to our query editor window 7147 02:40:25,860 --> 02:40:28,280 to our query editor window first we need to insert the order so 7148 02:40:28,280 --> 02:40:28,290 first we need to insert the order so 7149 02:40:28,290 --> 02:40:32,270 first we need to insert the order so insert in term let me close the 7150 02:40:32,270 --> 02:40:32,280 insert in term let me close the 7151 02:40:32,280 --> 02:40:35,060 insert in term let me close the navigator panel alright you want to 7152 02:40:35,060 --> 02:40:35,070 navigator panel alright you want to 7153 02:40:35,070 --> 02:40:36,730 navigator panel alright you want to insert a record into the orders table 7154 02:40:36,730 --> 02:40:36,740 insert a record into the orders table 7155 02:40:36,740 --> 02:40:40,190 insert a record into the orders table now what columns do we have here so we 7156 02:40:40,190 --> 02:40:40,200 now what columns do we have here so we 7157 02:40:40,200 --> 02:40:41,751 now what columns do we have here so we have these columns but only the first 7158 02:40:41,751 --> 02:40:41,761 have these columns but only the first 7159 02:40:41,761 --> 02:40:44,511 have these columns but only the first four are required and actually the first 7160 02:40:44,511 --> 02:40:44,521 four are required and actually the first 7161 02:40:44,521 --> 02:40:45,740 four are required and actually the first one we don't want to worry about that 7162 02:40:45,740 --> 02:40:45,750 one we don't want to worry about that 7163 02:40:45,750 --> 02:40:47,780 one we don't want to worry about that because that's an auto increment column 7164 02:40:47,780 --> 02:40:47,790 because that's an auto increment column 7165 02:40:47,790 --> 02:40:49,881 because that's an auto increment column so we only want to supply values for 7166 02:40:49,881 --> 02:40:49,891 so we only want to supply values for 7167 02:40:49,891 --> 02:40:53,720 so we only want to supply values for customer ID order date and status so 7168 02:40:53,720 --> 02:40:53,730 customer ID order date and status so 7169 02:40:53,730 --> 02:40:56,030 customer ID order date and status so back to our query we're specifying those 7170 02:40:56,030 --> 02:40:56,040 back to our query we're specifying those 7171 02:40:56,040 --> 02:41:00,970 back to our query we're specifying those columns here customer ID order date and 7172 02:41:00,970 --> 02:41:00,980 columns here customer ID order date and 7173 02:41:00,980 --> 02:41:05,751 columns here customer ID order date and status now let's apply the values in the 7174 02:41:05,751 --> 02:41:05,761 status now let's apply the values in the 7175 02:41:05,761 --> 02:41:07,761 status now let's apply the values in the customer ID column we need to add a 7176 02:41:07,761 --> 02:41:07,771 customer ID column we need to add a 7177 02:41:07,771 --> 02:41:11,001 customer ID column we need to add a valid customer ID so let's have a quick 7178 02:41:11,001 --> 02:41:11,011 valid customer ID so let's have a quick 7179 02:41:11,011 --> 02:41:15,150 valid customer ID so let's have a quick look at our customers table there you go 7180 02:41:15,150 --> 02:41:15,160 look at our customers table there you go 7181 02:41:15,160 --> 02:41:18,060 look at our customers table there you go in this table we have eleven records so 7182 02:41:18,060 --> 02:41:18,070 in this table we have eleven records so 7183 02:41:18,070 --> 02:41:20,940 in this table we have eleven records so these are the valid customer IDs now 7184 02:41:20,940 --> 02:41:20,950 these are the valid customer IDs now 7185 02:41:20,950 --> 02:41:23,280 these are the valid customer IDs now back to our query let's use one for 7186 02:41:23,280 --> 02:41:23,290 back to our query let's use one for 7187 02:41:23,290 --> 02:41:27,810 back to our query let's use one for customer ID and then 2019 January the 7188 02:41:27,810 --> 02:41:27,820 customer ID and then 2019 January the 7189 02:41:27,820 --> 02:41:30,570 customer ID and then 2019 January the second for the order date and one for 7190 02:41:30,570 --> 02:41:30,580 second for the order date and one for 7191 02:41:30,580 --> 02:41:32,850 second for the order date and one for the order status once again in this 7192 02:41:32,850 --> 02:41:32,860 the order status once again in this 7193 02:41:32,860 --> 02:41:35,370 the order status once again in this column we need to insert a valid order 7194 02:41:35,370 --> 02:41:35,380 column we need to insert a valid order 7195 02:41:35,380 --> 02:41:39,150 column we need to insert a valid order status ID if we don't supply a valid ID 7196 02:41:39,150 --> 02:41:39,160 status ID if we don't supply a valid ID 7197 02:41:39,160 --> 02:41:42,330 status ID if we don't supply a valid ID my skill is gonna yell at us so we 7198 02:41:42,330 --> 02:41:42,340 my skill is gonna yell at us so we 7199 02:41:42,340 --> 02:41:44,219 my skill is gonna yell at us so we insert an order here now we need to 7200 02:41:44,219 --> 02:41:44,229 insert an order here now we need to 7201 02:41:44,229 --> 02:41:46,530 insert an order here now we need to insert the items now back to our order 7202 02:41:46,530 --> 02:41:46,540 insert the items now back to our order 7203 02:41:46,540 --> 02:41:49,590 insert the items now back to our order items table in this table we have this 7204 02:41:49,590 --> 02:41:49,600 items table in this table we have this 7205 02:41:49,600 --> 02:41:52,050 items table in this table we have this order ID column so here's the tricky 7206 02:41:52,050 --> 02:41:52,060 order ID column so here's the tricky 7207 02:41:52,060 --> 02:41:52,350 order ID column so here's the tricky part 7208 02:41:52,350 --> 02:41:52,360 part 7209 02:41:52,360 --> 02:41:55,800 part as soon as we insert an order my skill 7210 02:41:55,800 --> 02:41:55,810 as soon as we insert an order my skill 7211 02:41:55,810 --> 02:41:57,780 as soon as we insert an order my skill is going to generate an ID for our new 7212 02:41:57,780 --> 02:41:57,790 is going to generate an ID for our new 7213 02:41:57,790 --> 02:41:59,820 is going to generate an ID for our new order now we need to be able to access 7214 02:41:59,820 --> 02:41:59,830 order now we need to be able to access 7215 02:41:59,830 --> 02:42:02,940 order now we need to be able to access that ID in order to insert the items in 7216 02:42:02,940 --> 02:42:02,950 that ID in order to insert the items in 7217 02:42:02,950 --> 02:42:06,450 that ID in order to insert the items in this table how can we do that well back 7218 02:42:06,450 --> 02:42:06,460 this table how can we do that well back 7219 02:42:06,460 --> 02:42:09,450 this table how can we do that well back to a query editor window in my skill we 7220 02:42:09,450 --> 02:42:09,460 to a query editor window in my skill we 7221 02:42:09,460 --> 02:42:12,090 to a query editor window in my skill we have a bunch of built-in functions and a 7222 02:42:12,090 --> 02:42:12,100 have a bunch of built-in functions and a 7223 02:42:12,100 --> 02:42:13,800 have a bunch of built-in functions and a function is basically a piece of code 7224 02:42:13,800 --> 02:42:13,810 function is basically a piece of code 7225 02:42:13,810 --> 02:42:15,600 function is basically a piece of code that we can reuse just like the 7226 02:42:15,600 --> 02:42:15,610 that we can reuse just like the 7227 02:42:15,610 --> 02:42:18,210 that we can reuse just like the functions or features in your TV every 7228 02:42:18,210 --> 02:42:18,220 functions or features in your TV every 7229 02:42:18,220 --> 02:42:19,500 functions or features in your TV every TV comes with a bunch of built-in 7230 02:42:19,500 --> 02:42:19,510 TV comes with a bunch of built-in 7231 02:42:19,510 --> 02:42:22,230 TV comes with a bunch of built-in functions like power on power off change 7232 02:42:22,230 --> 02:42:22,240 functions like power on power off change 7233 02:42:22,240 --> 02:42:23,940 functions like power on power off change the volume change the channel and so on 7234 02:42:23,940 --> 02:42:23,950 the volume change the channel and so on 7235 02:42:23,950 --> 02:42:27,090 the volume change the channel and so on so MySQL and other database engines come 7236 02:42:27,090 --> 02:42:27,100 so MySQL and other database engines come 7237 02:42:27,100 --> 02:42:28,950 so MySQL and other database engines come with a bunch of built-in functions that 7238 02:42:28,950 --> 02:42:28,960 with a bunch of built-in functions that 7239 02:42:28,960 --> 02:42:31,770 with a bunch of built-in functions that we can use in our programs one of these 7240 02:42:31,770 --> 02:42:31,780 we can use in our programs one of these 7241 02:42:31,780 --> 02:42:36,389 we can use in our programs one of these functions is last insert ID we can call 7242 02:42:36,389 --> 02:42:36,399 functions is last insert ID we can call 7243 02:42:36,399 --> 02:42:38,219 functions is last insert ID we can call or execute this function by adding 7244 02:42:38,219 --> 02:42:38,229 or execute this function by adding 7245 02:42:38,229 --> 02:42:40,110 or execute this function by adding parentheses here and this would return 7246 02:42:40,110 --> 02:42:40,120 parentheses here and this would return 7247 02:42:40,120 --> 02:42:42,660 parentheses here and this would return the ID that mice cube generates when we 7248 02:42:42,660 --> 02:42:42,670 the ID that mice cube generates when we 7249 02:42:42,670 --> 02:42:45,719 the ID that mice cube generates when we insert a new row so before going any 7250 02:42:45,719 --> 02:42:45,729 insert a new row so before going any 7251 02:42:45,729 --> 02:42:48,570 insert a new row so before going any further let's just select this and make 7252 02:42:48,570 --> 02:42:48,580 further let's just select this and make 7253 02:42:48,580 --> 02:42:50,730 further let's just select this and make sure we get the right result now we have 7254 02:42:50,730 --> 02:42:50,740 sure we get the right result now we have 7255 02:42:50,740 --> 02:42:52,200 sure we get the right result now we have a syntax error here because we didn't 7256 02:42:52,200 --> 02:42:52,210 a syntax error here because we didn't 7257 02:42:52,210 --> 02:42:53,940 a syntax error here because we didn't terminate the first statement with a 7258 02:42:53,940 --> 02:42:53,950 terminate the first statement with a 7259 02:42:53,950 --> 02:42:56,310 terminate the first statement with a semicolon all right now let's execute 7260 02:42:56,310 --> 02:42:56,320 semicolon all right now let's execute 7261 02:42:56,320 --> 02:42:59,639 semicolon all right now let's execute this query all right so the idea of the 7262 02:42:59,639 --> 02:42:59,649 this query all right so the idea of the 7263 02:42:59,649 --> 02:43:03,420 this query all right so the idea of the new order is 12 let's verify that so 7264 02:43:03,420 --> 02:43:03,430 new order is 12 let's verify that so 7265 02:43:03,430 --> 02:43:05,310 new order is 12 let's verify that so back to the orders table let's look at 7266 02:43:05,310 --> 02:43:05,320 back to the orders table let's look at 7267 02:43:05,320 --> 02:43:08,820 back to the orders table let's look at the data on my machine I have 12 records 7268 02:43:08,820 --> 02:43:08,830 the data on my machine I have 12 records 7269 02:43:08,830 --> 02:43:10,800 the data on my machine I have 12 records here I actually created one just before 7270 02:43:10,800 --> 02:43:10,810 here I actually created one just before 7271 02:43:10,810 --> 02:43:13,050 here I actually created one just before recording this video so on your machine 7272 02:43:13,050 --> 02:43:13,060 recording this video so on your machine 7273 02:43:13,060 --> 02:43:15,810 recording this video so on your machine you're gonna have 11 orders 7274 02:43:15,810 --> 02:43:15,820 you're gonna have 11 orders 7275 02:43:15,820 --> 02:43:18,180 you're gonna have 11 orders now back to our query window now that we 7276 02:43:18,180 --> 02:43:18,190 now back to our query window now that we 7277 02:43:18,190 --> 02:43:19,920 now back to our query window now that we know how to get the idea of the newly 7278 02:43:19,920 --> 02:43:19,930 know how to get the idea of the newly 7279 02:43:19,930 --> 02:43:22,261 know how to get the idea of the newly inserted record we can use that ID to 7280 02:43:22,261 --> 02:43:22,271 inserted record we can use that ID to 7281 02:43:22,271 --> 02:43:26,490 inserted record we can use that ID to insert the child records so we're going 7282 02:43:26,490 --> 02:43:26,500 insert the child records so we're going 7283 02:43:26,500 --> 02:43:29,130 insert the child records so we're going to write another insert statement insert 7284 02:43:29,130 --> 02:43:29,140 to write another insert statement insert 7285 02:43:29,140 --> 02:43:33,120 to write another insert statement insert into order items let's have another look 7286 02:43:33,120 --> 02:43:33,130 into order items let's have another look 7287 02:43:33,130 --> 02:43:35,670 into order items let's have another look at the columns in this table so we have 7288 02:43:35,670 --> 02:43:35,680 at the columns in this table so we have 7289 02:43:35,680 --> 02:43:37,320 at the columns in this table so we have four columns on all of them are required 7290 02:43:37,320 --> 02:43:37,330 four columns on all of them are required 7291 02:43:37,330 --> 02:43:39,330 four columns on all of them are required so there is really no need to specify 7292 02:43:39,330 --> 02:43:39,340 so there is really no need to specify 7293 02:43:39,340 --> 02:43:41,670 so there is really no need to specify the column names in our insert statement 7294 02:43:41,670 --> 02:43:41,680 the column names in our insert statement 7295 02:43:41,680 --> 02:43:44,040 the column names in our insert statement we simply supply values for order ID 7296 02:43:44,040 --> 02:43:44,050 we simply supply values for order ID 7297 02:43:44,050 --> 02:43:47,780 we simply supply values for order ID product ID quantity and unit price so 7298 02:43:47,780 --> 02:43:47,790 product ID quantity and unit price so 7299 02:43:47,790 --> 02:43:51,180 product ID quantity and unit price so here in the values Clause we had 7300 02:43:51,180 --> 02:43:51,190 here in the values Clause we had 7301 02:43:51,190 --> 02:43:54,630 here in the values Clause we had parentheses what is our order ID that is 7302 02:43:54,630 --> 02:43:54,640 parentheses what is our order ID that is 7303 02:43:54,640 --> 02:43:57,090 parentheses what is our order ID that is the value returned from calling this 7304 02:43:57,090 --> 02:43:57,100 the value returned from calling this 7305 02:43:57,100 --> 02:43:58,890 the value returned from calling this function so I'm going to cut this from 7306 02:43:58,890 --> 02:43:58,900 function so I'm going to cut this from 7307 02:43:58,900 --> 02:44:01,950 function so I'm going to cut this from here and put it here next we need to 7308 02:44:01,950 --> 02:44:01,960 here and put it here next we need to 7309 02:44:01,960 --> 02:44:04,350 here and put it here next we need to supply a valid product ID let's say 7310 02:44:04,350 --> 02:44:04,360 supply a valid product ID let's say 7311 02:44:04,360 --> 02:44:08,400 supply a valid product ID let's say product 1 quantity let's say 1 and the 7312 02:44:08,400 --> 02:44:08,410 product 1 quantity let's say 1 and the 7313 02:44:08,410 --> 02:44:11,540 product 1 quantity let's say 1 and the unit price to point $95 7314 02:44:11,540 --> 02:44:11,550 unit price to point $95 7315 02:44:11,550 --> 02:44:13,890 unit price to point $95 now let's delete this select we don't 7316 02:44:13,890 --> 02:44:13,900 now let's delete this select we don't 7317 02:44:13,900 --> 02:44:16,920 now let's delete this select we don't really need it anymore and let's add 7318 02:44:16,920 --> 02:44:16,930 really need it anymore and let's add 7319 02:44:16,930 --> 02:44:19,560 really need it anymore and let's add another set of values so once again 7320 02:44:19,560 --> 02:44:19,570 another set of values so once again 7321 02:44:19,570 --> 02:44:22,170 another set of values so once again we're gonna call last insert ID to get 7322 02:44:22,170 --> 02:44:22,180 we're gonna call last insert ID to get 7323 02:44:22,180 --> 02:44:24,240 we're gonna call last insert ID to get the idea of the new order we're gonna 7324 02:44:24,240 --> 02:44:24,250 the idea of the new order we're gonna 7325 02:44:24,250 --> 02:44:25,980 the idea of the new order we're gonna change the product to product number 2 7326 02:44:25,980 --> 02:44:25,990 change the product to product number 2 7327 02:44:25,990 --> 02:44:31,290 change the product to product number 2 and at a different price that's it now 7328 02:44:31,290 --> 02:44:31,300 and at a different price that's it now 7329 02:44:31,300 --> 02:44:32,820 and at a different price that's it now let's execute these statements and see 7330 02:44:32,820 --> 02:44:32,830 let's execute these statements and see 7331 02:44:32,830 --> 02:44:36,840 let's execute these statements and see what we get alright so back to our 7332 02:44:36,840 --> 02:44:36,850 what we get alright so back to our 7333 02:44:36,850 --> 02:44:39,390 what we get alright so back to our orders table let's refresh the records 7334 02:44:39,390 --> 02:44:39,400 orders table let's refresh the records 7335 02:44:39,400 --> 02:44:42,210 orders table let's refresh the records here alright so we have a new order 7336 02:44:42,210 --> 02:44:42,220 here alright so we have a new order 7337 02:44:42,220 --> 02:44:45,450 here alright so we have a new order order number 13 beautiful now let's look 7338 02:44:45,450 --> 02:44:45,460 order number 13 beautiful now let's look 7339 02:44:45,460 --> 02:44:47,850 order number 13 beautiful now let's look at the order items table here's the 7340 02:44:47,850 --> 02:44:47,860 at the order items table here's the 7341 02:44:47,860 --> 02:44:51,180 at the order items table here's the order items let's open the table so we 7342 02:44:51,180 --> 02:44:51,190 order items let's open the table so we 7343 02:44:51,190 --> 02:44:54,330 order items let's open the table so we should have two items for order number 7344 02:44:54,330 --> 02:44:54,340 should have two items for order number 7345 02:44:54,340 --> 02:44:57,300 should have two items for order number 13 beautiful so this is how you insert 7346 02:44:57,300 --> 02:44:57,310 13 beautiful so this is how you insert 7347 02:44:57,310 --> 02:45:04,830 13 beautiful so this is how you insert hierarchical data in MySQL 7348 02:45:04,830 --> 02:45:04,840 7349 02:45:04,840 --> 02:45:06,820 in this tutorial I'm going to show you 7350 02:45:06,820 --> 02:45:06,830 in this tutorial I'm going to show you 7351 02:45:06,830 --> 02:45:08,980 in this tutorial I'm going to show you how to copy data from one table to 7352 02:45:08,980 --> 02:45:08,990 how to copy data from one table to 7353 02:45:08,990 --> 02:45:11,530 how to copy data from one table to another for example in our orders table 7354 02:45:11,530 --> 02:45:11,540 another for example in our orders table 7355 02:45:11,540 --> 02:45:13,870 another for example in our orders table currently we have about a dozen records 7356 02:45:13,870 --> 02:45:13,880 currently we have about a dozen records 7357 02:45:13,880 --> 02:45:15,880 currently we have about a dozen records now let's say we want to create a copy 7358 02:45:15,880 --> 02:45:15,890 now let's say we want to create a copy 7359 02:45:15,890 --> 02:45:18,370 now let's say we want to create a copy of this table called orders archive and 7360 02:45:18,370 --> 02:45:18,380 of this table called orders archive and 7361 02:45:18,380 --> 02:45:20,530 of this table called orders archive and we want to insert every row that we have 7362 02:45:20,530 --> 02:45:20,540 we want to insert every row that we have 7363 02:45:20,540 --> 02:45:23,200 we want to insert every row that we have in this table into that new table if you 7364 02:45:23,200 --> 02:45:23,210 in this table into that new table if you 7365 02:45:23,210 --> 02:45:25,091 in this table into that new table if you have 10 orders we don't want to code an 7366 02:45:25,091 --> 02:45:25,101 have 10 orders we don't want to code an 7367 02:45:25,101 --> 02:45:27,520 have 10 orders we don't want to code an insert statement with 10 set of values 7368 02:45:27,520 --> 02:45:27,530 insert statement with 10 set of values 7369 02:45:27,530 --> 02:45:29,801 insert statement with 10 set of values that is very time-consuming so I'm going 7370 02:45:29,801 --> 02:45:29,811 that is very time-consuming so I'm going 7371 02:45:29,811 --> 02:45:31,570 that is very time-consuming so I'm going to show you a powerful technique to 7372 02:45:31,570 --> 02:45:31,580 to show you a powerful technique to 7373 02:45:31,580 --> 02:45:33,341 to show you a powerful technique to quickly copy data from one table to 7374 02:45:33,341 --> 02:45:33,351 quickly copy data from one table to 7375 02:45:33,351 --> 02:45:35,650 quickly copy data from one table to another first we need to create this new 7376 02:45:35,650 --> 02:45:35,660 another first we need to create this new 7377 02:45:35,660 --> 02:45:38,560 another first we need to create this new table orders archive for that we're 7378 02:45:38,560 --> 02:45:38,570 table orders archive for that we're 7379 02:45:38,570 --> 02:45:41,770 table orders archive for that we're gonna use the create table as statement 7380 02:45:41,770 --> 02:45:41,780 gonna use the create table as statement 7381 02:45:41,780 --> 02:45:48,520 gonna use the create table as statement so create table orders archived as now 7382 02:45:48,520 --> 02:45:48,530 so create table orders archived as now 7383 02:45:48,530 --> 02:45:50,860 so create table orders archived as now right after that we write a select 7384 02:45:50,860 --> 02:45:50,870 right after that we write a select 7385 02:45:50,870 --> 02:45:54,370 right after that we write a select statement to get everything from the 7386 02:45:54,370 --> 02:45:54,380 statement to get everything from the 7387 02:45:54,380 --> 02:45:57,490 statement to get everything from the orders table now let's see what happens 7388 02:45:57,490 --> 02:45:57,500 orders table now let's see what happens 7389 02:45:57,500 --> 02:45:59,830 orders table now let's see what happens when we execute this query there you go 7390 02:45:59,830 --> 02:45:59,840 when we execute this query there you go 7391 02:45:59,840 --> 02:46:03,100 when we execute this query there you go so back in the Navigator panel we have 7392 02:46:03,100 --> 02:46:03,110 so back in the Navigator panel we have 7393 02:46:03,110 --> 02:46:04,930 so back in the Navigator panel we have to refresh this view by clicking on this 7394 02:46:04,930 --> 02:46:04,940 to refresh this view by clicking on this 7395 02:46:04,940 --> 02:46:08,860 to refresh this view by clicking on this icon over here now we have a new table 7396 02:46:08,860 --> 02:46:08,870 icon over here now we have a new table 7397 02:46:08,870 --> 02:46:13,091 icon over here now we have a new table orders archive let's look at the data so 7398 02:46:13,091 --> 02:46:13,101 orders archive let's look at the data so 7399 02:46:13,101 --> 02:46:14,710 orders archive let's look at the data so you can see all the orders are here and 7400 02:46:14,710 --> 02:46:14,720 you can see all the orders are here and 7401 02:46:14,720 --> 02:46:16,750 you can see all the orders are here and we have the exact same columns as the 7402 02:46:16,750 --> 02:46:16,760 we have the exact same columns as the 7403 02:46:16,760 --> 02:46:19,301 we have the exact same columns as the orders table however if you open this 7404 02:46:19,301 --> 02:46:19,311 orders table however if you open this 7405 02:46:19,311 --> 02:46:22,180 orders table however if you open this table in the design mode you can see 7406 02:46:22,180 --> 02:46:22,190 table in the design mode you can see 7407 02:46:22,190 --> 02:46:23,740 table in the design mode you can see that in this table we don't have a 7408 02:46:23,740 --> 02:46:23,750 that in this table we don't have a 7409 02:46:23,750 --> 02:46:26,470 that in this table we don't have a primary key so the order ID column is 7410 02:46:26,470 --> 02:46:26,480 primary key so the order ID column is 7411 02:46:26,480 --> 02:46:29,170 primary key so the order ID column is not marked as a primary key and also 7412 02:46:29,170 --> 02:46:29,180 not marked as a primary key and also 7413 02:46:29,180 --> 02:46:30,761 not marked as a primary key and also it's not marked as an auto increment 7414 02:46:30,761 --> 02:46:30,771 it's not marked as an auto increment 7415 02:46:30,771 --> 02:46:33,070 it's not marked as an auto increment column so when we create a table using 7416 02:46:33,070 --> 02:46:33,080 column so when we create a table using 7417 02:46:33,080 --> 02:46:34,930 column so when we create a table using this technique my skill will ignore 7418 02:46:34,930 --> 02:46:34,940 this technique my skill will ignore 7419 02:46:34,940 --> 02:46:37,390 this technique my skill will ignore these attributes and that means if you 7420 02:46:37,390 --> 02:46:37,400 these attributes and that means if you 7421 02:46:37,400 --> 02:46:40,330 these attributes and that means if you want to explicitly insert a record into 7422 02:46:40,330 --> 02:46:40,340 want to explicitly insert a record into 7423 02:46:40,340 --> 02:46:42,610 want to explicitly insert a record into this new table we have to supply a value 7424 02:46:42,610 --> 02:46:42,620 this new table we have to supply a value 7425 02:46:42,620 --> 02:46:45,100 this new table we have to supply a value for order ID because this column is no 7426 02:46:45,100 --> 02:46:45,110 for order ID because this column is no 7427 02:46:45,110 --> 02:46:49,320 for order ID because this column is no longer an auto increment column okay so 7428 02:46:49,320 --> 02:46:49,330 longer an auto increment column okay so 7429 02:46:49,330 --> 02:46:52,030 longer an auto increment column okay so using Create table as statement you can 7430 02:46:52,030 --> 02:46:52,040 using Create table as statement you can 7431 02:46:52,040 --> 02:46:55,210 using Create table as statement you can quickly create a copy of a table now we 7432 02:46:55,210 --> 02:46:55,220 quickly create a copy of a table now we 7433 02:46:55,220 --> 02:46:57,400 quickly create a copy of a table now we refer to this select statement as a 7434 02:46:57,400 --> 02:46:57,410 refer to this select statement as a 7435 02:46:57,410 --> 02:47:00,310 refer to this select statement as a sub-query so a sub-query is a select 7436 02:47:00,310 --> 02:47:00,320 sub-query so a sub-query is a select 7437 02:47:00,320 --> 02:47:03,100 sub-query so a sub-query is a select statement that is part of another sequel 7438 02:47:03,100 --> 02:47:03,110 statement that is part of another sequel 7439 02:47:03,110 --> 02:47:05,200 statement that is part of another sequel statement now we can also use a 7440 02:47:05,200 --> 02:47:05,210 statement now we can also use a 7441 02:47:05,210 --> 02:47:07,450 statement now we can also use a sub-query in an insert statement and 7442 02:47:07,450 --> 02:47:07,460 sub-query in an insert statement and 7443 02:47:07,460 --> 02:47:09,460 sub-query in an insert statement and that's a very powerful technique it 7444 02:47:09,460 --> 02:47:09,470 that's a very powerful technique it 7445 02:47:09,470 --> 02:47:11,410 that's a very powerful technique it allows us to do really cool things let 7446 02:47:11,410 --> 02:47:11,420 allows us to do really cool things let 7447 02:47:11,420 --> 02:47:11,920 allows us to do really cool things let me show you 7448 02:47:11,920 --> 02:47:11,930 me show you 7449 02:47:11,930 --> 02:47:14,470 me show you so first let's right-click 7450 02:47:14,470 --> 02:47:14,480 so first let's right-click 7451 02:47:14,480 --> 02:47:17,980 so first let's right-click the orders archive table and click on 7452 02:47:17,980 --> 02:47:17,990 the orders archive table and click on 7453 02:47:17,990 --> 02:47:19,990 the orders archive table and click on truncate table because we want to delete 7454 02:47:19,990 --> 02:47:20,000 truncate table because we want to delete 7455 02:47:20,000 --> 02:47:23,081 truncate table because we want to delete all the data in this table all right is 7456 02:47:23,081 --> 02:47:23,091 all the data in this table all right is 7457 02:47:23,091 --> 02:47:24,461 all the data in this table all right is asking for confirmation 7458 02:47:24,461 --> 02:47:24,471 asking for confirmation 7459 02:47:24,471 --> 02:47:27,341 asking for confirmation let's truncate the table so now back to 7460 02:47:27,341 --> 02:47:27,351 let's truncate the table so now back to 7461 02:47:27,351 --> 02:47:30,610 let's truncate the table so now back to this table let's refresh the table we 7462 02:47:30,610 --> 02:47:30,620 this table let's refresh the table we 7463 02:47:30,620 --> 02:47:33,490 this table let's refresh the table we don't have any records here ok now back 7464 02:47:33,490 --> 02:47:33,500 don't have any records here ok now back 7465 02:47:33,500 --> 02:47:35,560 don't have any records here ok now back to a query editor let's say we want to 7466 02:47:35,560 --> 02:47:35,570 to a query editor let's say we want to 7467 02:47:35,570 --> 02:47:37,961 to a query editor let's say we want to copy only a subset of records from the 7468 02:47:37,961 --> 02:47:37,971 copy only a subset of records from the 7469 02:47:37,971 --> 02:47:40,150 copy only a subset of records from the orders table into this table like all 7470 02:47:40,150 --> 02:47:40,160 orders table into this table like all 7471 02:47:40,160 --> 02:47:43,360 orders table into this table like all the orders placed before 2019 so first 7472 02:47:43,360 --> 02:47:43,370 the orders placed before 2019 so first 7473 02:47:43,370 --> 02:47:46,060 the orders placed before 2019 so first let's select everything from the orders 7474 02:47:46,060 --> 02:47:46,070 let's select everything from the orders 7475 02:47:46,070 --> 02:47:50,650 let's select everything from the orders table where order date is less than 20 7476 02:47:50,650 --> 02:47:50,660 table where order date is less than 20 7477 02:47:50,660 --> 02:47:55,930 table where order date is less than 20 19 January 1st so these are all the 7478 02:47:55,930 --> 02:47:55,940 19 January 1st so these are all the 7479 02:47:55,940 --> 02:47:58,751 19 January 1st so these are all the orders orders number 2 to 10 beautiful 7480 02:47:58,751 --> 02:47:58,761 orders orders number 2 to 10 beautiful 7481 02:47:58,761 --> 02:48:01,331 orders orders number 2 to 10 beautiful now we want to copy these orders into 7482 02:48:01,331 --> 02:48:01,341 now we want to copy these orders into 7483 02:48:01,341 --> 02:48:05,671 now we want to copy these orders into the orders archive table so 7484 02:48:05,671 --> 02:48:05,681 the orders archive table so 7485 02:48:05,681 --> 02:48:07,560 the orders archive table so we can use this select statement as a 7486 02:48:07,560 --> 02:48:07,570 we can use this select statement as a 7487 02:48:07,570 --> 02:48:11,461 we can use this select statement as a sub-query in an insert statement we 7488 02:48:11,461 --> 02:48:11,471 sub-query in an insert statement we 7489 02:48:11,471 --> 02:48:16,980 sub-query in an insert statement we write insert into orders archive now we 7490 02:48:16,980 --> 02:48:16,990 write insert into orders archive now we 7491 02:48:16,990 --> 02:48:18,841 write insert into orders archive now we don't need to supply the column names 7492 02:48:18,841 --> 02:48:18,851 don't need to supply the column names 7493 02:48:18,851 --> 02:48:21,030 don't need to supply the column names because we're gonna supply values for 7494 02:48:21,030 --> 02:48:21,040 because we're gonna supply values for 7495 02:48:21,040 --> 02:48:23,631 because we're gonna supply values for every column that we have in this query 7496 02:48:23,631 --> 02:48:23,641 every column that we have in this query 7497 02:48:23,641 --> 02:48:26,341 every column that we have in this query so we did it dad 7498 02:48:26,341 --> 02:48:26,351 so we did it dad 7499 02:48:26,351 --> 02:48:30,900 so we did it dad and this is an example of using a select 7500 02:48:30,900 --> 02:48:30,910 and this is an example of using a select 7501 02:48:30,910 --> 02:48:33,450 and this is an example of using a select statement as a sub query in an insert 7502 02:48:33,450 --> 02:48:33,460 statement as a sub query in an insert 7503 02:48:33,460 --> 02:48:37,261 statement as a sub query in an insert statement let's execute this alright now 7504 02:48:37,261 --> 02:48:37,271 statement let's execute this alright now 7505 02:48:37,271 --> 02:48:39,780 statement let's execute this alright now back to the table let's refresh the 7506 02:48:39,780 --> 02:48:39,790 back to the table let's refresh the 7507 02:48:39,790 --> 02:48:42,511 back to the table let's refresh the records we only have the orders placed 7508 02:48:42,511 --> 02:48:42,521 records we only have the orders placed 7509 02:48:42,521 --> 02:48:48,580 records we only have the orders placed before 2019 7510 02:48:48,580 --> 02:48:48,590 7511 02:48:48,590 --> 02:48:51,051 alright here's a really really really 7512 02:48:51,051 --> 02:48:51,061 alright here's a really really really 7513 02:48:51,061 --> 02:48:53,480 alright here's a really really really cool exercise for you back to our sequel 7514 02:48:53,480 --> 02:48:53,490 cool exercise for you back to our sequel 7515 02:48:53,490 --> 02:48:55,940 cool exercise for you back to our sequel invoicing database look at the invoices 7516 02:48:55,940 --> 02:48:55,950 invoicing database look at the invoices 7517 02:48:55,950 --> 02:48:59,060 invoicing database look at the invoices table so in this table we have these 7518 02:48:59,060 --> 02:48:59,070 table so in this table we have these 7519 02:48:59,070 --> 02:49:02,330 table so in this table we have these columns English ID number client ID 7520 02:49:02,330 --> 02:49:02,340 columns English ID number client ID 7521 02:49:02,340 --> 02:49:05,180 columns English ID number client ID which is associated or related to the 7522 02:49:05,180 --> 02:49:05,190 which is associated or related to the 7523 02:49:05,190 --> 02:49:07,301 which is associated or related to the client ID column in the clients table 7524 02:49:07,301 --> 02:49:07,311 client ID column in the clients table 7525 02:49:07,311 --> 02:49:09,920 client ID column in the clients table followed by a few other columns now 7526 02:49:09,920 --> 02:49:09,930 followed by a few other columns now 7527 02:49:09,930 --> 02:49:11,480 followed by a few other columns now let's say we want to create a copy of 7528 02:49:11,480 --> 02:49:11,490 let's say we want to create a copy of 7529 02:49:11,490 --> 02:49:13,580 let's say we want to create a copy of the records in this table and put them 7530 02:49:13,580 --> 02:49:13,590 the records in this table and put them 7531 02:49:13,590 --> 02:49:16,360 the records in this table and put them in a new table called invoices archive 7532 02:49:16,360 --> 02:49:16,370 in a new table called invoices archive 7533 02:49:16,370 --> 02:49:19,551 in a new table called invoices archive however in that table instead of the 7534 02:49:19,551 --> 02:49:19,561 however in that table instead of the 7535 02:49:19,561 --> 02:49:21,591 however in that table instead of the client ID column we want to have the 7536 02:49:21,591 --> 02:49:21,601 client ID column we want to have the 7537 02:49:21,601 --> 02:49:23,630 client ID column we want to have the client name column so you need to join 7538 02:49:23,630 --> 02:49:23,640 client name column so you need to join 7539 02:49:23,640 --> 02:49:25,370 client name column so you need to join the same ol with the clients table and 7540 02:49:25,370 --> 02:49:25,380 the same ol with the clients table and 7541 02:49:25,380 --> 02:49:27,830 the same ol with the clients table and then use that query as a sub query in a 7542 02:49:27,830 --> 02:49:27,840 then use that query as a sub query in a 7543 02:49:27,840 --> 02:49:30,530 then use that query as a sub query in a create table statement also to make the 7544 02:49:30,530 --> 02:49:30,540 create table statement also to make the 7545 02:49:30,540 --> 02:49:32,600 create table statement also to make the exercise more interesting I want you to 7546 02:49:32,600 --> 02:49:32,610 exercise more interesting I want you to 7547 02:49:32,610 --> 02:49:34,850 exercise more interesting I want you to copy only the invoices that do have a 7548 02:49:34,850 --> 02:49:34,860 copy only the invoices that do have a 7549 02:49:34,860 --> 02:49:38,540 copy only the invoices that do have a payment so if you look over here this 7550 02:49:38,540 --> 02:49:38,550 payment so if you look over here this 7551 02:49:38,550 --> 02:49:40,490 payment so if you look over here this payment date column determines if a 7552 02:49:40,490 --> 02:49:40,500 payment date column determines if a 7553 02:49:40,500 --> 02:49:42,470 payment date column determines if a payment has been made towards this 7554 02:49:42,470 --> 02:49:42,480 payment has been made towards this 7555 02:49:42,480 --> 02:49:43,430 payment has been made towards this invoice or not 7556 02:49:43,430 --> 02:49:43,440 invoice or not 7557 02:49:43,440 --> 02:49:45,890 invoice or not so select only the invoices that do have 7558 02:49:45,890 --> 02:49:45,900 so select only the invoices that do have 7559 02:49:45,900 --> 02:49:48,230 so select only the invoices that do have a payment date it's a really really good 7560 02:49:48,230 --> 02:49:48,240 a payment date it's a really really good 7561 02:49:48,240 --> 02:49:50,480 a payment date it's a really really good exercise spend 2 to 3 minutes on this 7562 02:49:50,480 --> 02:49:50,490 exercise spend 2 to 3 minutes on this 7563 02:49:50,490 --> 02:49:53,490 exercise spend 2 to 3 minutes on this and then come back continue watching 7564 02:49:53,490 --> 02:49:53,500 and then come back continue watching 7565 02:49:53,500 --> 02:49:56,700 and then come back continue watching you 7566 02:49:56,700 --> 02:49:56,710 7567 02:49:56,710 --> 02:49:58,350 all right fair 7568 02:49:58,350 --> 02:49:58,360 all right fair 7569 02:49:58,360 --> 02:50:00,751 all right fair I'm gonna use the sequel invoicing 7570 02:50:00,751 --> 02:50:00,761 I'm gonna use the sequel invoicing 7571 02:50:00,761 --> 02:50:03,350 I'm gonna use the sequel invoicing database now let's select everything 7572 02:50:03,350 --> 02:50:03,360 database now let's select everything 7573 02:50:03,360 --> 02:50:07,381 database now let's select everything from the invoices table and join it with 7574 02:50:07,381 --> 02:50:07,391 from the invoices table and join it with 7575 02:50:07,391 --> 02:50:10,501 from the invoices table and join it with the clients table here I'm gonna use the 7576 02:50:10,501 --> 02:50:10,511 the clients table here I'm gonna use the 7577 02:50:10,511 --> 02:50:12,631 the clients table here I'm gonna use the using statement to simplify my joint 7578 02:50:12,631 --> 02:50:12,641 using statement to simplify my joint 7579 02:50:12,641 --> 02:50:14,820 using statement to simplify my joint what column are we gonna use for joining 7580 02:50:14,820 --> 02:50:14,830 what column are we gonna use for joining 7581 02:50:14,830 --> 02:50:18,841 what column are we gonna use for joining the client ID column let's execute this 7582 02:50:18,841 --> 02:50:18,851 the client ID column let's execute this 7583 02:50:18,851 --> 02:50:22,291 the client ID column let's execute this query up to this point alright so first 7584 02:50:22,291 --> 02:50:22,301 query up to this point alright so first 7585 02:50:22,301 --> 02:50:24,450 query up to this point alright so first we see the client ID column that is used 7586 02:50:24,450 --> 02:50:24,460 we see the client ID column that is used 7587 02:50:24,460 --> 02:50:27,240 we see the client ID column that is used for joining these tables after that we 7588 02:50:27,240 --> 02:50:27,250 for joining these tables after that we 7589 02:50:27,250 --> 02:50:29,131 for joining these tables after that we have the columns from the invoices table 7590 02:50:29,131 --> 02:50:29,141 have the columns from the invoices table 7591 02:50:29,141 --> 02:50:30,980 have the columns from the invoices table like invoice ID number and so on 7592 02:50:30,980 --> 02:50:30,990 like invoice ID number and so on 7593 02:50:30,990 --> 02:50:34,921 like invoice ID number and so on followed by the columns from the clients 7594 02:50:34,921 --> 02:50:34,931 followed by the columns from the clients 7595 02:50:34,931 --> 02:50:37,190 followed by the columns from the clients table like name address and so on 7596 02:50:37,190 --> 02:50:37,200 table like name address and so on 7597 02:50:37,200 --> 02:50:39,030 table like name address and so on obviously we don't want all of these 7598 02:50:39,030 --> 02:50:39,040 obviously we don't want all of these 7599 02:50:39,040 --> 02:50:41,041 obviously we don't want all of these columns we only need the columns from 7600 02:50:41,041 --> 02:50:41,051 columns we only need the columns from 7601 02:50:41,051 --> 02:50:43,320 columns we only need the columns from the invoices table but we should replace 7602 02:50:43,320 --> 02:50:43,330 the invoices table but we should replace 7603 02:50:43,330 --> 02:50:45,570 the invoices table but we should replace the client ID column with the client 7604 02:50:45,570 --> 02:50:45,580 the client ID column with the client 7605 02:50:45,580 --> 02:50:49,051 the client ID column with the client name column so let's have a quick look 7606 02:50:49,051 --> 02:50:49,061 name column so let's have a quick look 7607 02:50:49,061 --> 02:50:53,970 name column so let's have a quick look at the design of the invoices table here 7608 02:50:53,970 --> 02:50:53,980 at the design of the invoices table here 7609 02:50:53,980 --> 02:50:56,910 at the design of the invoices table here we have invoices ID number client ID we 7610 02:50:56,910 --> 02:50:56,920 we have invoices ID number client ID we 7611 02:50:56,920 --> 02:50:58,501 we have invoices ID number client ID we want to replace this column with the 7612 02:50:58,501 --> 02:50:58,511 want to replace this column with the 7613 02:50:58,511 --> 02:51:02,290 want to replace this column with the client name so back to our query 7614 02:51:02,290 --> 02:51:02,300 client name so back to our query 7615 02:51:02,300 --> 02:51:07,859 client name so back to our query I'm gonna pick a moist ID number and 7616 02:51:07,859 --> 02:51:07,869 I'm gonna pick a moist ID number and 7617 02:51:07,869 --> 02:51:11,769 I'm gonna pick a moist ID number and then client that name let's rename it to 7618 02:51:11,769 --> 02:51:11,779 then client that name let's rename it to 7619 02:51:11,779 --> 02:51:14,649 then client that name let's rename it to client what other columns do we have 7620 02:51:14,649 --> 02:51:14,659 client what other columns do we have 7621 02:51:14,659 --> 02:51:17,920 client what other columns do we have here we have invoice total and payment 7622 02:51:17,920 --> 02:51:17,930 here we have invoice total and payment 7623 02:51:17,930 --> 02:51:20,069 here we have invoice total and payment total so let's add those as well 7624 02:51:20,069 --> 02:51:20,079 total so let's add those as well 7625 02:51:20,079 --> 02:51:24,359 total so let's add those as well invoice total as well as payment total 7626 02:51:24,359 --> 02:51:24,369 invoice total as well as payment total 7627 02:51:24,369 --> 02:51:28,569 invoice total as well as payment total we also have three columns for dates 7628 02:51:28,569 --> 02:51:28,579 we also have three columns for dates 7629 02:51:28,579 --> 02:51:31,420 we also have three columns for dates invoice date due date and payment date 7630 02:51:31,420 --> 02:51:31,430 invoice date due date and payment date 7631 02:51:31,430 --> 02:51:35,099 invoice date due date and payment date so let me close the navigator panel 7632 02:51:35,099 --> 02:51:35,109 so let me close the navigator panel 7633 02:51:35,109 --> 02:51:41,050 so let me close the navigator panel invoice date payment date and due date 7634 02:51:41,050 --> 02:51:41,060 invoice date payment date and due date 7635 02:51:41,060 --> 02:51:43,120 invoice date payment date and due date now technically because these columns 7636 02:51:43,120 --> 02:51:43,130 now technically because these columns 7637 02:51:43,130 --> 02:51:46,149 now technically because these columns only exist in the invoices table we 7638 02:51:46,149 --> 02:51:46,159 only exist in the invoices table we 7639 02:51:46,159 --> 02:51:48,309 only exist in the invoices table we don't have to prefix them with a table 7640 02:51:48,309 --> 02:51:48,319 don't have to prefix them with a table 7641 02:51:48,319 --> 02:51:51,130 don't have to prefix them with a table alias so we could simplify the code like 7642 02:51:51,130 --> 02:51:51,140 alias so we could simplify the code like 7643 02:51:51,140 --> 02:51:53,500 alias so we could simplify the code like this however I personally prefer to 7644 02:51:53,500 --> 02:51:53,510 this however I personally prefer to 7645 02:51:53,510 --> 02:51:55,719 this however I personally prefer to prefix them because that gives me a more 7646 02:51:55,719 --> 02:51:55,729 prefix them because that gives me a more 7647 02:51:55,729 --> 02:51:57,550 prefix them because that gives me a more clear picture of how I'm joining these 7648 02:51:57,550 --> 02:51:57,560 clear picture of how I'm joining these 7649 02:51:57,560 --> 02:51:59,559 clear picture of how I'm joining these tables it's just a personal preference 7650 02:51:59,559 --> 02:51:59,569 tables it's just a personal preference 7651 02:51:59,569 --> 02:52:01,450 tables it's just a personal preference another developer might disagree and 7652 02:52:01,450 --> 02:52:01,460 another developer might disagree and 7653 02:52:01,460 --> 02:52:03,370 another developer might disagree and that's perfectly fine so whatever you 7654 02:52:03,370 --> 02:52:03,380 that's perfectly fine so whatever you 7655 02:52:03,380 --> 02:52:06,670 that's perfectly fine so whatever you prefer that's perfectly fine let's 7656 02:52:06,670 --> 02:52:06,680 prefer that's perfectly fine let's 7657 02:52:06,680 --> 02:52:08,710 prefer that's perfectly fine let's execute the query and make sure we get 7658 02:52:08,710 --> 02:52:08,720 execute the query and make sure we get 7659 02:52:08,720 --> 02:52:12,219 execute the query and make sure we get the right result so we have the invoice 7660 02:52:12,219 --> 02:52:12,229 the right result so we have the invoice 7661 02:52:12,229 --> 02:52:15,939 the right result so we have the invoice ID number client beautiful followed by 7662 02:52:15,939 --> 02:52:15,949 ID number client beautiful followed by 7663 02:52:15,949 --> 02:52:18,550 ID number client beautiful followed by these other columns now I'm going to 7664 02:52:18,550 --> 02:52:18,560 these other columns now I'm going to 7665 02:52:18,560 --> 02:52:20,800 these other columns now I'm going to filter the result and return only the 7666 02:52:20,800 --> 02:52:20,810 filter the result and return only the 7667 02:52:20,810 --> 02:52:23,710 filter the result and return only the invoices that do have a payment so we 7668 02:52:23,710 --> 02:52:23,720 invoices that do have a payment so we 7669 02:52:23,720 --> 02:52:25,540 invoices that do have a payment so we can either return records that have a 7670 02:52:25,540 --> 02:52:25,550 can either return records that have a 7671 02:52:25,550 --> 02:52:28,660 can either return records that have a payment date or the records that have a 7672 02:52:28,660 --> 02:52:28,670 payment date or the records that have a 7673 02:52:28,670 --> 02:52:31,689 payment date or the records that have a payment total of greater than zero those 7674 02:52:31,689 --> 02:52:31,699 payment total of greater than zero those 7675 02:52:31,699 --> 02:52:35,309 payment total of greater than zero those are perfectly fine so back to our query 7676 02:52:35,309 --> 02:52:35,319 are perfectly fine so back to our query 7677 02:52:35,319 --> 02:52:38,279 are perfectly fine so back to our query down the bottom let's add a where clause 7678 02:52:38,279 --> 02:52:38,289 down the bottom let's add a where clause 7679 02:52:38,289 --> 02:52:43,420 down the bottom let's add a where clause where payment date is not no that's 7680 02:52:43,420 --> 02:52:43,430 where payment date is not no that's 7681 02:52:43,430 --> 02:52:45,399 where payment date is not no that's better let's execute the query one more 7682 02:52:45,399 --> 02:52:45,409 better let's execute the query one more 7683 02:52:45,409 --> 02:52:48,670 better let's execute the query one more time now we get only this handful of 7684 02:52:48,670 --> 02:52:48,680 time now we get only this handful of 7685 02:52:48,680 --> 02:52:52,029 time now we get only this handful of invoices beautiful finally let's use our 7686 02:52:52,029 --> 02:52:52,039 invoices beautiful finally let's use our 7687 02:52:52,039 --> 02:52:55,630 invoices beautiful finally let's use our query as a sub query in a create table 7688 02:52:55,630 --> 02:52:55,640 query as a sub query in a create table 7689 02:52:55,640 --> 02:52:58,450 query as a sub query in a create table as statement 7690 02:52:58,450 --> 02:52:58,460 as statement 7691 02:52:58,460 --> 02:53:02,091 as statement so right before select we type create 7692 02:53:02,091 --> 02:53:02,101 so right before select we type create 7693 02:53:02,101 --> 02:53:07,131 so right before select we type create table invoices archived as there you go 7694 02:53:07,131 --> 02:53:07,141 table invoices archived as there you go 7695 02:53:07,141 --> 02:53:10,610 table invoices archived as there you go let's execute the Quai beautiful now 7696 02:53:10,610 --> 02:53:10,620 let's execute the Quai beautiful now 7697 02:53:10,620 --> 02:53:12,621 let's execute the Quai beautiful now back to the Navigator panel let's 7698 02:53:12,621 --> 02:53:12,631 back to the Navigator panel let's 7699 02:53:12,631 --> 02:53:15,860 back to the Navigator panel let's refresh the view so here's our new table 7700 02:53:15,860 --> 02:53:15,870 refresh the view so here's our new table 7701 02:53:15,870 --> 02:53:18,490 refresh the view so here's our new table invoices archive let's look at the data 7702 02:53:18,490 --> 02:53:18,500 invoices archive let's look at the data 7703 02:53:18,500 --> 02:53:22,430 invoices archive let's look at the data there you go we only have the invoices 7704 02:53:22,430 --> 02:53:22,440 there you go we only have the invoices 7705 02:53:22,440 --> 02:53:24,950 there you go we only have the invoices paid and here's the name of the client 7706 02:53:24,950 --> 02:53:24,960 paid and here's the name of the client 7707 02:53:24,960 --> 02:53:27,831 paid and here's the name of the client for each invoice beautiful now just note 7708 02:53:27,831 --> 02:53:27,841 for each invoice beautiful now just note 7709 02:53:27,841 --> 02:53:29,450 for each invoice beautiful now just note that if you execute this query one more 7710 02:53:29,450 --> 02:53:29,460 that if you execute this query one more 7711 02:53:29,460 --> 02:53:30,921 that if you execute this query one more time you're gonna get an error because 7712 02:53:30,921 --> 02:53:30,931 time you're gonna get an error because 7713 02:53:30,931 --> 02:53:33,650 time you're gonna get an error because we already have a table called invoices 7714 02:53:33,650 --> 02:53:33,660 we already have a table called invoices 7715 02:53:33,660 --> 02:53:35,660 we already have a table called invoices archive later in the course I'll show 7716 02:53:35,660 --> 02:53:35,670 archive later in the course I'll show 7717 02:53:35,670 --> 02:53:37,371 archive later in the course I'll show you how to drop tables that's pretty 7718 02:53:37,371 --> 02:53:37,381 you how to drop tables that's pretty 7719 02:53:37,381 --> 02:53:39,140 you how to drop tables that's pretty easy but for now you can just right 7720 02:53:39,140 --> 02:53:39,150 easy but for now you can just right 7721 02:53:39,150 --> 02:53:43,700 easy but for now you can just right click and go to drop table and then 7722 02:53:43,700 --> 02:53:43,710 click and go to drop table and then 7723 02:53:43,710 --> 02:53:46,131 click and go to drop table and then confirm all right and then you can run 7724 02:53:46,131 --> 02:53:46,141 confirm all right and then you can run 7725 02:53:46,141 --> 02:53:52,130 confirm all right and then you can run the query in one more time 7726 02:53:52,130 --> 02:53:52,140 7727 02:53:52,140 --> 02:53:54,660 in this tutorial I'm going to show you 7728 02:53:54,660 --> 02:53:54,670 in this tutorial I'm going to show you 7729 02:53:54,670 --> 02:53:57,899 in this tutorial I'm going to show you how to update data in sequa so back to 7730 02:53:57,899 --> 02:53:57,909 how to update data in sequa so back to 7731 02:53:57,909 --> 02:54:01,319 how to update data in sequa so back to our invoices table look at the first 7732 02:54:01,319 --> 02:54:01,329 our invoices table look at the first 7733 02:54:01,329 --> 02:54:04,439 our invoices table look at the first record here the payment total for this 7734 02:54:04,439 --> 02:54:04,449 record here the payment total for this 7735 02:54:04,449 --> 02:54:06,840 record here the payment total for this record is zero and obviously there is no 7736 02:54:06,840 --> 02:54:06,850 record is zero and obviously there is no 7737 02:54:06,850 --> 02:54:09,240 record is zero and obviously there is no payment date now let's imagine that 7738 02:54:09,240 --> 02:54:09,250 payment date now let's imagine that 7739 02:54:09,250 --> 02:54:10,710 payment date now let's imagine that there was a problem in the system that 7740 02:54:10,710 --> 02:54:10,720 there was a problem in the system that 7741 02:54:10,720 --> 02:54:13,080 there was a problem in the system that recorded this information let's say the 7742 02:54:13,080 --> 02:54:13,090 recorded this information let's say the 7743 02:54:13,090 --> 02:54:15,870 recorded this information let's say the client paid $10 for this invoice so we 7744 02:54:15,870 --> 02:54:15,880 client paid $10 for this invoice so we 7745 02:54:15,880 --> 02:54:17,399 client paid $10 for this invoice so we should update this record in this table 7746 02:54:17,399 --> 02:54:17,409 should update this record in this table 7747 02:54:17,409 --> 02:54:20,130 should update this record in this table that is very easy back to our query 7748 02:54:20,130 --> 02:54:20,140 that is very easy back to our query 7749 02:54:20,140 --> 02:54:22,260 that is very easy back to our query editor window we use the update 7750 02:54:22,260 --> 02:54:22,270 editor window we use the update 7751 02:54:22,270 --> 02:54:24,389 editor window we use the update statement to update one or more records 7752 02:54:24,389 --> 02:54:24,399 statement to update one or more records 7753 02:54:24,399 --> 02:54:25,050 statement to update one or more records in a table 7754 02:54:25,050 --> 02:54:25,060 in a table 7755 02:54:25,060 --> 02:54:28,649 in a table what table in this case invoices next we 7756 02:54:28,649 --> 02:54:28,659 what table in this case invoices next we 7757 02:54:28,659 --> 02:54:31,109 what table in this case invoices next we had the set clause and this is where we 7758 02:54:31,109 --> 02:54:31,119 had the set clause and this is where we 7759 02:54:31,119 --> 02:54:33,450 had the set clause and this is where we specify the new value for one or more 7760 02:54:33,450 --> 02:54:33,460 specify the new value for one or more 7761 02:54:33,460 --> 02:54:35,639 specify the new value for one or more columns in this case we want to update 7762 02:54:35,639 --> 02:54:35,649 columns in this case we want to update 7763 02:54:35,649 --> 02:54:39,330 columns in this case we want to update payment total let's set it to $10 we 7764 02:54:39,330 --> 02:54:39,340 payment total let's set it to $10 we 7765 02:54:39,340 --> 02:54:42,510 payment total let's set it to $10 we should also update payment date so we 7766 02:54:42,510 --> 02:54:42,520 should also update payment date so we 7767 02:54:42,520 --> 02:54:45,540 should also update payment date so we use a comma to add more columns we set 7768 02:54:45,540 --> 02:54:45,550 use a comma to add more columns we set 7769 02:54:45,550 --> 02:54:48,960 use a comma to add more columns we set this to a date value let's say 2019 7770 02:54:48,960 --> 02:54:48,970 this to a date value let's say 2019 7771 02:54:48,970 --> 02:54:52,710 this to a date value let's say 2019 March first and then we type out a 7772 02:54:52,710 --> 02:54:52,720 March first and then we type out a 7773 02:54:52,720 --> 02:54:55,349 March first and then we type out a condition with this condition we 7774 02:54:55,349 --> 02:54:55,359 condition with this condition we 7775 02:54:55,359 --> 02:54:57,359 condition with this condition we identified the record or the records 7776 02:54:57,359 --> 02:54:57,369 identified the record or the records 7777 02:54:57,369 --> 02:54:59,700 identified the record or the records that need to be updated in this case we 7778 02:54:59,700 --> 02:54:59,710 that need to be updated in this case we 7779 02:54:59,710 --> 02:55:04,260 that need to be updated in this case we want to update the invoice number one so 7780 02:55:04,260 --> 02:55:04,270 want to update the invoice number one so 7781 02:55:04,270 --> 02:55:07,649 want to update the invoice number one so back to our query we type out invoice ID 7782 02:55:07,649 --> 02:55:07,659 back to our query we type out invoice ID 7783 02:55:07,659 --> 02:55:10,700 back to our query we type out invoice ID equal to one let's execute this 7784 02:55:10,700 --> 02:55:10,710 equal to one let's execute this 7785 02:55:10,710 --> 02:55:14,010 equal to one let's execute this beautiful now back to our table let's 7786 02:55:14,010 --> 02:55:14,020 beautiful now back to our table let's 7787 02:55:14,020 --> 02:55:15,689 beautiful now back to our table let's refresh the data by clicking on this 7788 02:55:15,689 --> 02:55:15,699 refresh the data by clicking on this 7789 02:55:15,699 --> 02:55:18,780 refresh the data by clicking on this icon all right you can see payment total 7790 02:55:18,780 --> 02:55:18,790 icon all right you can see payment total 7791 02:55:18,790 --> 02:55:21,450 icon all right you can see payment total is updated to ten and we also have a 7792 02:55:21,450 --> 02:55:21,460 is updated to ten and we also have a 7793 02:55:21,460 --> 02:55:24,090 is updated to ten and we also have a payment date beautiful now let's say we 7794 02:55:24,090 --> 02:55:24,100 payment date beautiful now let's say we 7795 02:55:24,100 --> 02:55:26,399 payment date beautiful now let's say we actually updated the wrong record maybe 7796 02:55:26,399 --> 02:55:26,409 actually updated the wrong record maybe 7797 02:55:26,409 --> 02:55:27,990 actually updated the wrong record maybe we should have updated in ways number 7798 02:55:27,990 --> 02:55:28,000 we should have updated in ways number 7799 02:55:28,000 --> 02:55:30,330 we should have updated in ways number three so we should update this table one 7800 02:55:30,330 --> 02:55:30,340 three so we should update this table one 7801 02:55:30,340 --> 02:55:32,219 three so we should update this table one more time and restore the original 7802 02:55:32,219 --> 02:55:32,229 more time and restore the original 7803 02:55:32,229 --> 02:55:35,240 more time and restore the original values in this columns back to a query 7804 02:55:35,240 --> 02:55:35,250 values in this columns back to a query 7805 02:55:35,250 --> 02:55:39,109 values in this columns back to a query we can set the payment total to zero and 7806 02:55:39,109 --> 02:55:39,119 we can set the payment total to zero and 7807 02:55:39,119 --> 02:55:44,099 we can set the payment total to zero and the payment date to know so we can use 7808 02:55:44,099 --> 02:55:44,109 the payment date to know so we can use 7809 02:55:44,109 --> 02:55:45,990 the payment date to know so we can use the null keyword to insert the null 7810 02:55:45,990 --> 02:55:46,000 the null keyword to insert the null 7811 02:55:46,000 --> 02:55:48,330 the null keyword to insert the null value in a column that accepts null 7812 02:55:48,330 --> 02:55:48,340 value in a column that accepts null 7813 02:55:48,340 --> 02:55:50,870 value in a column that accepts null values now back to the Navigator panel 7814 02:55:50,870 --> 02:55:50,880 values now back to the Navigator panel 7815 02:55:50,880 --> 02:55:53,599 values now back to the Navigator panel let's open this table in the design mode 7816 02:55:53,599 --> 02:55:53,609 let's open this table in the design mode 7817 02:55:53,609 --> 02:55:55,950 let's open this table in the design mode you can see that the payment total 7818 02:55:55,950 --> 02:55:55,960 you can see that the payment total 7819 02:55:55,960 --> 02:55:58,500 you can see that the payment total column has a default value of zero and 7820 02:55:58,500 --> 02:55:58,510 column has a default value of zero and 7821 02:55:58,510 --> 02:56:00,990 column has a default value of zero and the payment date column has the default 7822 02:56:00,990 --> 02:56:01,000 the payment date column has the default 7823 02:56:01,000 --> 02:56:02,131 the payment date column has the default value of No 7824 02:56:02,131 --> 02:56:02,141 value of No 7825 02:56:02,141 --> 02:56:04,831 value of No so back in our query we can also set 7826 02:56:04,831 --> 02:56:04,841 so back in our query we can also set 7827 02:56:04,841 --> 02:56:08,671 so back in our query we can also set payment total to default and MySQL will 7828 02:56:08,671 --> 02:56:08,681 payment total to default and MySQL will 7829 02:56:08,681 --> 02:56:10,381 payment total to default and MySQL will use the default value for this column 7830 02:56:10,381 --> 02:56:10,391 use the default value for this column 7831 02:56:10,391 --> 02:56:12,541 use the default value for this column which is in this case zero so let's 7832 02:56:12,541 --> 02:56:12,551 which is in this case zero so let's 7833 02:56:12,551 --> 02:56:14,301 which is in this case zero so let's execute this statement one more time 7834 02:56:14,301 --> 02:56:14,311 execute this statement one more time 7835 02:56:14,311 --> 02:56:17,370 execute this statement one more time beautiful now back to the table let's 7836 02:56:17,370 --> 02:56:17,380 beautiful now back to the table let's 7837 02:56:17,380 --> 02:56:20,520 beautiful now back to the table let's refresh the data so payment total is set 7838 02:56:20,520 --> 02:56:20,530 refresh the data so payment total is set 7839 02:56:20,530 --> 02:56:23,180 refresh the data so payment total is set to zero and payment date is not 7840 02:56:23,180 --> 02:56:23,190 to zero and payment date is not 7841 02:56:23,190 --> 02:56:25,890 to zero and payment date is not beautiful now let's go ahead and update 7842 02:56:25,890 --> 02:56:25,900 beautiful now let's go ahead and update 7843 02:56:25,900 --> 02:56:28,440 beautiful now let's go ahead and update the third payment look at the invoice 7844 02:56:28,440 --> 02:56:28,450 the third payment look at the invoice 7845 02:56:28,450 --> 02:56:30,331 the third payment look at the invoice total that is one hundred and 7846 02:56:30,331 --> 02:56:30,341 total that is one hundred and 7847 02:56:30,341 --> 02:56:32,461 total that is one hundred and forty-seven dollars for this example 7848 02:56:32,461 --> 02:56:32,471 forty-seven dollars for this example 7849 02:56:32,471 --> 02:56:35,520 forty-seven dollars for this example let's imagine that the client made fifty 7850 02:56:35,520 --> 02:56:35,530 let's imagine that the client made fifty 7851 02:56:35,530 --> 02:56:37,980 let's imagine that the client made fifty percent of the total amount on the due 7852 02:56:37,980 --> 02:56:37,990 percent of the total amount on the due 7853 02:56:37,990 --> 02:56:41,220 percent of the total amount on the due date so back to our query editor window 7854 02:56:41,220 --> 02:56:41,230 date so back to our query editor window 7855 02:56:41,230 --> 02:56:43,650 date so back to our query editor window instead of using a literal value here 7856 02:56:43,650 --> 02:56:43,660 instead of using a literal value here 7857 02:56:43,660 --> 02:56:45,570 instead of using a literal value here like seventy dollars we can write an 7858 02:56:45,570 --> 02:56:45,580 like seventy dollars we can write an 7859 02:56:45,580 --> 02:56:48,690 like seventy dollars we can write an expression we want to calculate 50% of 7860 02:56:48,690 --> 02:56:48,700 expression we want to calculate 50% of 7861 02:56:48,700 --> 02:56:54,091 expression we want to calculate 50% of invoice total so invoice total times 0.5 7862 02:56:54,091 --> 02:56:54,101 invoice total so invoice total times 0.5 7863 02:56:54,101 --> 02:56:56,850 invoice total so invoice total times 0.5 now let me break this code into multiple 7864 02:56:56,850 --> 02:56:56,860 now let me break this code into multiple 7865 02:56:56,860 --> 02:57:00,030 now let me break this code into multiple lines so we can see clearly now we 7866 02:57:00,030 --> 02:57:00,040 lines so we can see clearly now we 7867 02:57:00,040 --> 02:57:02,370 lines so we can see clearly now we should set the payment date as I told 7868 02:57:02,370 --> 02:57:02,380 should set the payment date as I told 7869 02:57:02,380 --> 02:57:04,950 should set the payment date as I told you this client made the payment on the 7870 02:57:04,950 --> 02:57:04,960 you this client made the payment on the 7871 02:57:04,960 --> 02:57:08,100 you this client made the payment on the due date so we can set this to Jew date 7872 02:57:08,100 --> 02:57:08,110 due date so we can set this to Jew date 7873 02:57:08,110 --> 02:57:10,350 due date so we can set this to Jew date whatever value we have in this column 7874 02:57:10,350 --> 02:57:10,360 whatever value we have in this column 7875 02:57:10,360 --> 02:57:13,470 whatever value we have in this column will be used to set the payment date and 7876 02:57:13,470 --> 02:57:13,480 will be used to set the payment date and 7877 02:57:13,480 --> 02:57:15,240 will be used to set the payment date and obviously we need to update the invoice 7878 02:57:15,240 --> 02:57:15,250 obviously we need to update the invoice 7879 02:57:15,250 --> 02:57:18,470 obviously we need to update the invoice ID number three now back in the table 7880 02:57:18,470 --> 02:57:18,480 ID number three now back in the table 7881 02:57:18,480 --> 02:57:22,171 ID number three now back in the table let's refresh the data all right look 7882 02:57:22,171 --> 02:57:22,181 let's refresh the data all right look 7883 02:57:22,181 --> 02:57:24,961 let's refresh the data all right look payment total is updated and it said to 7884 02:57:24,961 --> 02:57:24,971 payment total is updated and it said to 7885 02:57:24,971 --> 02:57:27,990 payment total is updated and it said to almost 50 percent of the invoice total 7886 02:57:27,990 --> 02:57:28,000 almost 50 percent of the invoice total 7887 02:57:28,000 --> 02:57:30,360 almost 50 percent of the invoice total however this number is truncated so we 7888 02:57:30,360 --> 02:57:30,370 however this number is truncated so we 7889 02:57:30,370 --> 02:57:31,770 however this number is truncated so we don't have two digits after the decimal 7890 02:57:31,770 --> 02:57:31,780 don't have two digits after the decimal 7891 02:57:31,780 --> 02:57:33,900 don't have two digits after the decimal point don't worry about it for now we'll 7892 02:57:33,900 --> 02:57:33,910 point don't worry about it for now we'll 7893 02:57:33,910 --> 02:57:34,980 point don't worry about it for now we'll come back to this when we talk about 7894 02:57:34,980 --> 02:57:34,990 come back to this when we talk about 7895 02:57:34,990 --> 02:57:37,890 come back to this when we talk about data types later in the course also you 7896 02:57:37,890 --> 02:57:37,900 data types later in the course also you 7897 02:57:37,900 --> 02:57:40,381 data types later in the course also you can see that payment date is set to the 7898 02:57:40,381 --> 02:57:40,391 can see that payment date is set to the 7899 02:57:40,391 --> 02:57:42,211 can see that payment date is set to the same value we have in the due date 7900 02:57:42,211 --> 02:57:42,221 same value we have in the due date 7901 02:57:42,221 --> 02:57:47,781 same value we have in the due date column 7902 02:57:47,781 --> 02:57:47,791 7903 02:57:47,791 --> 02:57:50,100 in the last tutorial you learned how to 7904 02:57:50,100 --> 02:57:50,110 in the last tutorial you learned how to 7905 02:57:50,110 --> 02:57:52,501 in the last tutorial you learned how to update a single record using the update 7906 02:57:52,501 --> 02:57:52,511 update a single record using the update 7907 02:57:52,511 --> 02:57:54,150 update a single record using the update statement now if you want to update 7908 02:57:54,150 --> 02:57:54,160 statement now if you want to update 7909 02:57:54,160 --> 02:57:56,640 statement now if you want to update multiple records the syntax is exactly 7910 02:57:56,640 --> 02:57:56,650 multiple records the syntax is exactly 7911 02:57:56,650 --> 02:57:58,621 multiple records the syntax is exactly the same but the condition that you type 7912 02:57:58,621 --> 02:57:58,631 the same but the condition that you type 7913 02:57:58,631 --> 02:58:00,871 the same but the condition that you type out here has to be more general for 7914 02:58:00,871 --> 02:58:00,881 out here has to be more general for 7915 02:58:00,881 --> 02:58:03,541 out here has to be more general for example back to the invoices table you 7916 02:58:03,541 --> 02:58:03,551 example back to the invoices table you 7917 02:58:03,551 --> 02:58:05,071 example back to the invoices table you can see that we have multiple invoices 7918 02:58:05,071 --> 02:58:05,081 can see that we have multiple invoices 7919 02:58:05,081 --> 02:58:08,041 can see that we have multiple invoices for client number three we can write a 7920 02:58:08,041 --> 02:58:08,051 for client number three we can write a 7921 02:58:08,051 --> 02:58:10,531 for client number three we can write a statement to update all the invoices for 7922 02:58:10,531 --> 02:58:10,541 statement to update all the invoices for 7923 02:58:10,541 --> 02:58:12,690 statement to update all the invoices for this client so back to our query editor 7924 02:58:12,690 --> 02:58:12,700 this client so back to our query editor 7925 02:58:12,700 --> 02:58:16,081 this client so back to our query editor window we change our condition to where 7926 02:58:16,081 --> 02:58:16,091 window we change our condition to where 7927 02:58:16,091 --> 02:58:20,281 window we change our condition to where client ID equals to three however if you 7928 02:58:20,281 --> 02:58:20,291 client ID equals to three however if you 7929 02:58:20,291 --> 02:58:22,171 client ID equals to three however if you execute this statement with MySQL 7930 02:58:22,171 --> 02:58:22,181 execute this statement with MySQL 7931 02:58:22,181 --> 02:58:23,791 execute this statement with MySQL workbench which is the software we've 7932 02:58:23,791 --> 02:58:23,801 workbench which is the software we've 7933 02:58:23,801 --> 02:58:25,261 workbench which is the software we've been using in this course you're gonna 7934 02:58:25,261 --> 02:58:25,271 been using in this course you're gonna 7935 02:58:25,271 --> 02:58:27,690 been using in this course you're gonna get an error because by default MySQL 7936 02:58:27,690 --> 02:58:27,700 get an error because by default MySQL 7937 02:58:27,700 --> 02:58:30,480 get an error because by default MySQL workbench runs in the safe update mode 7938 02:58:30,480 --> 02:58:30,490 workbench runs in the safe update mode 7939 02:58:30,490 --> 02:58:32,911 workbench runs in the safe update mode so it allows you to update only a single 7940 02:58:32,911 --> 02:58:32,921 so it allows you to update only a single 7941 02:58:32,921 --> 02:58:34,411 so it allows you to update only a single record you're not gonna have this 7942 02:58:34,411 --> 02:58:34,421 record you're not gonna have this 7943 02:58:34,421 --> 02:58:36,301 record you're not gonna have this problem if you use another client for 7944 02:58:36,301 --> 02:58:36,311 problem if you use another client for 7945 02:58:36,311 --> 02:58:38,911 problem if you use another client for MySQL or if you write this statement in 7946 02:58:38,911 --> 02:58:38,921 MySQL or if you write this statement in 7947 02:58:38,921 --> 02:58:40,980 MySQL or if you write this statement in your application code this is only 7948 02:58:40,980 --> 02:58:40,990 your application code this is only 7949 02:58:40,990 --> 02:58:44,551 your application code this is only specific to MySQL workbench now let me 7950 02:58:44,551 --> 02:58:44,561 specific to MySQL workbench now let me 7951 02:58:44,561 --> 02:58:46,680 specific to MySQL workbench now let me show you how to get around this so on 7952 02:58:46,680 --> 02:58:46,690 show you how to get around this so on 7953 02:58:46,690 --> 02:58:49,411 show you how to get around this so on the top we go to MySQL workbench menu 7954 02:58:49,411 --> 02:58:49,421 the top we go to MySQL workbench menu 7955 02:58:49,421 --> 02:58:53,341 the top we go to MySQL workbench menu and then preferences on this dialog box 7956 02:58:53,341 --> 02:58:53,351 and then preferences on this dialog box 7957 02:58:53,351 --> 02:58:56,371 and then preferences on this dialog box on the left side click on sequel editor 7958 02:58:56,371 --> 02:58:56,381 on the left side click on sequel editor 7959 02:58:56,381 --> 02:59:01,411 on the left side click on sequel editor and then down the bottom untick this 7960 02:59:01,411 --> 02:59:01,421 and then down the bottom untick this 7961 02:59:01,421 --> 02:59:04,711 and then down the bottom untick this check box save updates so this prevents 7962 02:59:04,711 --> 02:59:04,721 check box save updates so this prevents 7963 02:59:04,721 --> 02:59:06,360 check box save updates so this prevents you from accidentally updating or 7964 02:59:06,360 --> 02:59:06,370 you from accidentally updating or 7965 02:59:06,370 --> 02:59:07,860 you from accidentally updating or deleting a bunch of records in a table 7966 02:59:07,860 --> 02:59:07,870 deleting a bunch of records in a table 7967 02:59:07,870 --> 02:59:12,031 deleting a bunch of records in a table so let's go ahead with this now we need 7968 02:59:12,031 --> 02:59:12,041 so let's go ahead with this now we need 7969 02:59:12,041 --> 02:59:14,161 so let's go ahead with this now we need to reconnect to this instance of MySQL 7970 02:59:14,161 --> 02:59:14,171 to reconnect to this instance of MySQL 7971 02:59:14,171 --> 02:59:18,121 to reconnect to this instance of MySQL so let's copy all the code here and 7972 02:59:18,121 --> 02:59:18,131 so let's copy all the code here and 7973 02:59:18,131 --> 02:59:22,051 so let's copy all the code here and close this local instance window alright 7974 02:59:22,051 --> 02:59:22,061 close this local instance window alright 7975 02:59:22,061 --> 02:59:24,360 close this local instance window alright now on the home page double click this 7976 02:59:24,360 --> 02:59:24,370 now on the home page double click this 7977 02:59:24,370 --> 02:59:27,081 now on the home page double click this connection to reconnect there you go and 7978 02:59:27,081 --> 02:59:27,091 connection to reconnect there you go and 7979 02:59:27,091 --> 02:59:31,411 connection to reconnect there you go and then paste all that sequel code now 7980 02:59:31,411 --> 02:59:31,421 then paste all that sequel code now 7981 02:59:31,421 --> 02:59:34,411 then paste all that sequel code now let's execute this beautiful all the 7982 02:59:34,411 --> 02:59:34,421 let's execute this beautiful all the 7983 02:59:34,421 --> 02:59:36,301 let's execute this beautiful all the invoices for client number three were 7984 02:59:36,301 --> 02:59:36,311 invoices for client number three were 7985 02:59:36,311 --> 02:59:38,791 invoices for client number three were updated here we can also use the in 7986 02:59:38,791 --> 02:59:38,801 updated here we can also use the in 7987 02:59:38,801 --> 02:59:40,890 updated here we can also use the in operator let's say we want to update all 7988 02:59:40,890 --> 02:59:40,900 operator let's say we want to update all 7989 02:59:40,900 --> 02:59:43,020 operator let's say we want to update all the invoices for clients number three 7990 02:59:43,020 --> 02:59:43,030 the invoices for clients number three 7991 02:59:43,030 --> 02:59:45,810 the invoices for clients number three and number four so all the operators you 7992 02:59:45,810 --> 02:59:45,820 and number four so all the operators you 7993 02:59:45,820 --> 02:59:47,761 and number four so all the operators you learn to use in the where clause also 7994 02:59:47,761 --> 02:59:47,771 learn to use in the where clause also 7995 02:59:47,771 --> 02:59:50,461 learn to use in the where clause also apply here now technically this where 7996 02:59:50,461 --> 02:59:50,471 apply here now technically this where 7997 02:59:50,471 --> 02:59:52,650 apply here now technically this where Clause is optional so if you want to 7998 02:59:52,650 --> 02:59:52,660 Clause is optional so if you want to 7999 02:59:52,660 --> 02:59:54,961 Clause is optional so if you want to update all the records in a table you 8000 02:59:54,961 --> 02:59:54,971 update all the records in a table you 8001 02:59:54,971 --> 02:59:56,970 update all the records in a table you simply leave it out 8002 02:59:56,970 --> 02:59:56,980 simply leave it out 8003 02:59:56,980 --> 03:00:00,301 simply leave it out you 8004 03:00:00,301 --> 03:00:00,311 8005 03:00:00,311 --> 03:00:03,730 our user exercise for this tutorial back 8006 03:00:03,730 --> 03:00:03,740 our user exercise for this tutorial back 8007 03:00:03,740 --> 03:00:05,801 our user exercise for this tutorial back to our sequence to our database write 8008 03:00:05,801 --> 03:00:05,811 to our sequence to our database write 8009 03:00:05,811 --> 03:00:07,780 to our sequence to our database write the sequel statement to give any 8010 03:00:07,780 --> 03:00:07,790 the sequel statement to give any 8011 03:00:07,790 --> 03:00:12,160 the sequel statement to give any customers born before 1990 50 extra 8012 03:00:12,160 --> 03:00:12,170 customers born before 1990 50 extra 8013 03:00:12,170 --> 03:00:14,211 customers born before 1990 50 extra points 8014 03:00:14,211 --> 03:00:14,221 points 8015 03:00:14,221 --> 03:00:17,550 points you 8016 03:00:17,550 --> 03:00:17,560 8017 03:00:17,560 --> 03:00:20,969 alright first I'm gonna use sequel store 8018 03:00:20,969 --> 03:00:20,979 alright first I'm gonna use sequel store 8019 03:00:20,979 --> 03:00:24,219 alright first I'm gonna use sequel store then write an update statement to update 8020 03:00:24,219 --> 03:00:24,229 then write an update statement to update 8021 03:00:24,229 --> 03:00:27,969 then write an update statement to update the customers table set the points two 8022 03:00:27,969 --> 03:00:27,979 the customers table set the points two 8023 03:00:27,979 --> 03:00:30,760 the customers table set the points two points plus 50 so here we are using an 8024 03:00:30,760 --> 03:00:30,770 points plus 50 so here we are using an 8025 03:00:30,770 --> 03:00:33,210 points plus 50 so here we are using an expression to update the points column 8026 03:00:33,210 --> 03:00:33,220 expression to update the points column 8027 03:00:33,220 --> 03:00:37,689 expression to update the points column for anyone born before 1990 so where 8028 03:00:37,689 --> 03:00:37,699 for anyone born before 1990 so where 8029 03:00:37,699 --> 03:00:42,639 for anyone born before 1990 so where birth date is less than 1990 January 8030 03:00:42,639 --> 03:00:42,649 birth date is less than 1990 January 8031 03:00:42,649 --> 03:00:43,979 birth date is less than 1990 January first 8032 03:00:43,979 --> 03:00:43,989 first 8033 03:00:43,989 --> 03:00:47,290 first alright let's execute this query alright 8034 03:00:47,290 --> 03:00:47,300 alright let's execute this query alright 8035 03:00:47,300 --> 03:00:50,080 alright let's execute this query alright now let's open up the customers table 8036 03:00:50,080 --> 03:00:50,090 now let's open up the customers table 8037 03:00:50,090 --> 03:00:52,250 now let's open up the customers table one more time 8038 03:00:52,250 --> 03:00:52,260 one more time 8039 03:00:52,260 --> 03:00:55,131 one more time so anyone who was born before 1990 now 8040 03:00:55,131 --> 03:00:55,141 so anyone who was born before 1990 now 8041 03:00:55,141 --> 03:01:01,830 so anyone who was born before 1990 now has an extra 50 points 8042 03:01:01,830 --> 03:01:01,840 8043 03:01:01,840 --> 03:01:04,480 in this tutorial you're gonna learn how 8044 03:01:04,480 --> 03:01:04,490 in this tutorial you're gonna learn how 8045 03:01:04,490 --> 03:01:06,280 in this tutorial you're gonna learn how to use sub-queries in an update 8046 03:01:06,280 --> 03:01:06,290 to use sub-queries in an update 8047 03:01:06,290 --> 03:01:08,920 to use sub-queries in an update statement that's extremely powerful so 8048 03:01:08,920 --> 03:01:08,930 statement that's extremely powerful so 8049 03:01:08,930 --> 03:01:10,179 statement that's extremely powerful so we're gonna continue with the example 8050 03:01:10,179 --> 03:01:10,189 we're gonna continue with the example 8051 03:01:10,189 --> 03:01:12,099 we're gonna continue with the example from the last tutorial but we're gonna 8052 03:01:12,099 --> 03:01:12,109 from the last tutorial but we're gonna 8053 03:01:12,109 --> 03:01:14,110 from the last tutorial but we're gonna make it more interesting here we're 8054 03:01:14,110 --> 03:01:14,120 make it more interesting here we're 8055 03:01:14,120 --> 03:01:16,450 make it more interesting here we're updating all the invoices for client 8056 03:01:16,450 --> 03:01:16,460 updating all the invoices for client 8057 03:01:16,460 --> 03:01:18,849 updating all the invoices for client number three but what if we don't have 8058 03:01:18,849 --> 03:01:18,859 number three but what if we don't have 8059 03:01:18,859 --> 03:01:20,710 number three but what if we don't have the idea of a client you only have the 8060 03:01:20,710 --> 03:01:20,720 the idea of a client you only have the 8061 03:01:20,720 --> 03:01:22,690 the idea of a client you only have the name for example imagine you have an 8062 03:01:22,690 --> 03:01:22,700 name for example imagine you have an 8063 03:01:22,700 --> 03:01:24,849 name for example imagine you have an application and in that application the 8064 03:01:24,849 --> 03:01:24,859 application and in that application the 8065 03:01:24,859 --> 03:01:27,460 application and in that application the user types in the name of the client so 8066 03:01:27,460 --> 03:01:27,470 user types in the name of the client so 8067 03:01:27,470 --> 03:01:29,050 user types in the name of the client so first we should find the ID for that 8068 03:01:29,050 --> 03:01:29,060 first we should find the ID for that 8069 03:01:29,060 --> 03:01:31,360 first we should find the ID for that client and then use that ID to update 8070 03:01:31,360 --> 03:01:31,370 client and then use that ID to update 8071 03:01:31,370 --> 03:01:33,700 client and then use that ID to update all their invoices how do we do that 8072 03:01:33,700 --> 03:01:33,710 all their invoices how do we do that 8073 03:01:33,710 --> 03:01:36,219 all their invoices how do we do that well let's have a quick look at our 8074 03:01:36,219 --> 03:01:36,229 well let's have a quick look at our 8075 03:01:36,229 --> 03:01:40,120 well let's have a quick look at our clients table so here we have this 8076 03:01:40,120 --> 03:01:40,130 clients table so here we have this 8077 03:01:40,130 --> 03:01:42,490 clients table so here we have this client my works let's say we have the 8078 03:01:42,490 --> 03:01:42,500 client my works let's say we have the 8079 03:01:42,500 --> 03:01:45,219 client my works let's say we have the name we want to find the ID so back to 8080 03:01:45,219 --> 03:01:45,229 name we want to find the ID so back to 8081 03:01:45,229 --> 03:01:47,620 name we want to find the ID so back to our query editor window after this 8082 03:01:47,620 --> 03:01:47,630 our query editor window after this 8083 03:01:47,630 --> 03:01:49,179 our query editor window after this update statement I'm gonna write a 8084 03:01:49,179 --> 03:01:49,189 update statement I'm gonna write a 8085 03:01:49,189 --> 03:01:52,059 update statement I'm gonna write a select statement to select the client ID 8086 03:01:52,059 --> 03:01:52,069 select statement to select the client ID 8087 03:01:52,069 --> 03:01:56,440 select statement to select the client ID column from the clients table where name 8088 03:01:56,440 --> 03:01:56,450 column from the clients table where name 8089 03:01:56,450 --> 03:02:00,370 column from the clients table where name equals my works now here we have a 8090 03:02:00,370 --> 03:02:00,380 equals my works now here we have a 8091 03:02:00,380 --> 03:02:01,840 equals my works now here we have a syntax error because we didn't terminate 8092 03:02:01,840 --> 03:02:01,850 syntax error because we didn't terminate 8093 03:02:01,850 --> 03:02:04,000 syntax error because we didn't terminate the last increment with a semicolon but 8094 03:02:04,000 --> 03:02:04,010 the last increment with a semicolon but 8095 03:02:04,010 --> 03:02:05,290 the last increment with a semicolon but don't worry about that we're gonna get 8096 03:02:05,290 --> 03:02:05,300 don't worry about that we're gonna get 8097 03:02:05,300 --> 03:02:07,269 don't worry about that we're gonna get back to that in a second let's just 8098 03:02:07,269 --> 03:02:07,279 back to that in a second let's just 8099 03:02:07,279 --> 03:02:09,550 back to that in a second let's just select these few lines and execute this 8100 03:02:09,550 --> 03:02:09,560 select these few lines and execute this 8101 03:02:09,560 --> 03:02:12,309 select these few lines and execute this query the idea of this client is too 8102 03:02:12,309 --> 03:02:12,319 query the idea of this client is too 8103 03:02:12,319 --> 03:02:15,400 query the idea of this client is too beautiful now we can use this select 8104 03:02:15,400 --> 03:02:15,410 beautiful now we can use this select 8105 03:02:15,410 --> 03:02:18,219 beautiful now we can use this select statement as a sub query in an update 8106 03:02:18,219 --> 03:02:18,229 statement as a sub query in an update 8107 03:02:18,229 --> 03:02:20,860 statement as a sub query in an update statement so as I told you before a sub 8108 03:02:20,860 --> 03:02:20,870 statement so as I told you before a sub 8109 03:02:20,870 --> 03:02:23,139 statement so as I told you before a sub query is a select statement that is 8110 03:02:23,139 --> 03:02:23,149 query is a select statement that is 8111 03:02:23,149 --> 03:02:26,320 query is a select statement that is within another sequel statement so 8112 03:02:26,320 --> 03:02:26,330 within another sequel statement so 8113 03:02:26,330 --> 03:02:27,790 within another sequel statement so instead of hard-coding 8114 03:02:27,790 --> 03:02:27,800 instead of hard-coding 8115 03:02:27,800 --> 03:02:31,000 instead of hard-coding 3 here we're gonna use this select 8116 03:02:31,000 --> 03:02:31,010 3 here we're gonna use this select 8117 03:02:31,010 --> 03:02:33,160 3 here we're gonna use this select statement as a sub query but we need to 8118 03:02:33,160 --> 03:02:33,170 statement as a sub query but we need to 8119 03:02:33,170 --> 03:02:36,370 statement as a sub query but we need to put it in parenthesis so MySQL will 8120 03:02:36,370 --> 03:02:36,380 put it in parenthesis so MySQL will 8121 03:02:36,380 --> 03:02:39,250 put it in parenthesis so MySQL will execute this query first it will return 8122 03:02:39,250 --> 03:02:39,260 execute this query first it will return 8123 03:02:39,260 --> 03:02:42,400 execute this query first it will return the client ID and then use it in this 8124 03:02:42,400 --> 03:02:42,410 the client ID and then use it in this 8125 03:02:42,410 --> 03:02:42,940 the client ID and then use it in this condition 8126 03:02:42,940 --> 03:02:42,950 condition 8127 03:02:42,950 --> 03:02:46,030 condition so for clarity let's remove the line 8128 03:02:46,030 --> 03:02:46,040 so for clarity let's remove the line 8129 03:02:46,040 --> 03:02:50,210 so for clarity let's remove the line break and indent these few lines 8130 03:02:50,210 --> 03:02:50,220 break and indent these few lines 8131 03:02:50,220 --> 03:02:53,449 break and indent these few lines so this is the end result now we execute 8132 03:02:53,449 --> 03:02:53,459 so this is the end result now we execute 8133 03:02:53,459 --> 03:02:55,639 so this is the end result now we execute this query and this updated all the 8134 03:02:55,639 --> 03:02:55,649 this query and this updated all the 8135 03:02:55,649 --> 03:02:58,069 this query and this updated all the invoices for this client now what if 8136 03:02:58,069 --> 03:02:58,079 invoices for this client now what if 8137 03:02:58,079 --> 03:03:01,010 invoices for this client now what if this query returns multiple clients for 8138 03:03:01,010 --> 03:03:01,020 this query returns multiple clients for 8139 03:03:01,020 --> 03:03:03,439 this query returns multiple clients for example back to the clients table let's 8140 03:03:03,439 --> 03:03:03,449 example back to the clients table let's 8141 03:03:03,449 --> 03:03:05,000 example back to the clients table let's imagine we want to update the invoices 8142 03:03:05,000 --> 03:03:05,010 imagine we want to update the invoices 8143 03:03:05,010 --> 03:03:07,969 imagine we want to update the invoices for all clients located in New York or 8144 03:03:07,969 --> 03:03:07,979 for all clients located in New York or 8145 03:03:07,979 --> 03:03:12,019 for all clients located in New York or California so we need to update our sub 8146 03:03:12,019 --> 03:03:12,029 California so we need to update our sub 8147 03:03:12,029 --> 03:03:17,679 California so we need to update our sub query like this where state in 8148 03:03:17,679 --> 03:03:17,689 query like this where state in 8149 03:03:17,689 --> 03:03:21,340 query like this where state in California and New York 8150 03:03:21,340 --> 03:03:21,350 California and New York 8151 03:03:21,350 --> 03:03:23,569 California and New York now before executing the entire 8152 03:03:23,569 --> 03:03:23,579 now before executing the entire 8153 03:03:23,579 --> 03:03:26,149 now before executing the entire statement let's just select our sub 8154 03:03:26,149 --> 03:03:26,159 statement let's just select our sub 8155 03:03:26,159 --> 03:03:28,489 statement let's just select our sub query and execute it to see what we get 8156 03:03:28,489 --> 03:03:28,499 query and execute it to see what we get 8157 03:03:28,499 --> 03:03:33,469 query and execute it to see what we get so we get to client IDs 1 & 3 beautiful 8158 03:03:33,469 --> 03:03:33,479 so we get to client IDs 1 & 3 beautiful 8159 03:03:33,479 --> 03:03:36,469 so we get to client IDs 1 & 3 beautiful now because this query this sub query 8160 03:03:36,469 --> 03:03:36,479 now because this query this sub query 8161 03:03:36,479 --> 03:03:39,710 now because this query this sub query returns multiple records we cannot use 8162 03:03:39,710 --> 03:03:39,720 returns multiple records we cannot use 8163 03:03:39,720 --> 03:03:42,080 returns multiple records we cannot use an equal sign here anymore so we need to 8164 03:03:42,080 --> 03:03:42,090 an equal sign here anymore so we need to 8165 03:03:42,090 --> 03:03:44,719 an equal sign here anymore so we need to replace this with the in operator and 8166 03:03:44,719 --> 03:03:44,729 replace this with the in operator and 8167 03:03:44,729 --> 03:03:47,149 replace this with the in operator and now this statement updates the invoices 8168 03:03:47,149 --> 03:03:47,159 now this statement updates the invoices 8169 03:03:47,159 --> 03:03:49,639 now this statement updates the invoices for all clients located in these two 8170 03:03:49,639 --> 03:03:49,649 for all clients located in these two 8171 03:03:49,649 --> 03:03:52,609 for all clients located in these two states let's execute it beautiful 8172 03:03:52,609 --> 03:03:52,619 states let's execute it beautiful 8173 03:03:52,619 --> 03:03:54,819 states let's execute it beautiful everything worked so as a best practice 8174 03:03:54,819 --> 03:03:54,829 everything worked so as a best practice 8175 03:03:54,829 --> 03:03:57,229 everything worked so as a best practice before executing your update statement 8176 03:03:57,229 --> 03:03:57,239 before executing your update statement 8177 03:03:57,239 --> 03:03:59,449 before executing your update statement run your query to see what records 8178 03:03:59,449 --> 03:03:59,459 run your query to see what records 8179 03:03:59,459 --> 03:04:00,500 run your query to see what records you're going to update so you don't 8180 03:04:00,500 --> 03:04:00,510 you're going to update so you don't 8181 03:04:00,510 --> 03:04:02,479 you're going to update so you don't accidentally update the records that 8182 03:04:02,479 --> 03:04:02,489 accidentally update the records that 8183 03:04:02,489 --> 03:04:04,609 accidentally update the records that shouldn't be updated now here we have a 8184 03:04:04,609 --> 03:04:04,619 shouldn't be updated now here we have a 8185 03:04:04,619 --> 03:04:06,710 shouldn't be updated now here we have a sub query but even if it didn't have a 8186 03:04:06,710 --> 03:04:06,720 sub query but even if it didn't have a 8187 03:04:06,720 --> 03:04:08,630 sub query but even if it didn't have a sub query you could still query the 8188 03:04:08,630 --> 03:04:08,640 sub query you could still query the 8189 03:04:08,640 --> 03:04:10,160 sub query you could still query the records that we're going to update let 8190 03:04:10,160 --> 03:04:10,170 records that we're going to update let 8191 03:04:10,170 --> 03:04:12,949 records that we're going to update let me show you so let's imagine we're going 8192 03:04:12,949 --> 03:04:12,959 me show you so let's imagine we're going 8193 03:04:12,959 --> 03:04:16,010 me show you so let's imagine we're going to update all the invoices where payment 8194 03:04:16,010 --> 03:04:16,020 to update all the invoices where payment 8195 03:04:16,020 --> 03:04:19,969 to update all the invoices where payment date is no before executing this entire 8196 03:04:19,969 --> 03:04:19,979 date is no before executing this entire 8197 03:04:19,979 --> 03:04:22,489 date is no before executing this entire update statement I would run a query 8198 03:04:22,489 --> 03:04:22,499 update statement I would run a query 8199 03:04:22,499 --> 03:04:26,540 update statement I would run a query like this select star from invoices 8200 03:04:26,540 --> 03:04:26,550 like this select star from invoices 8201 03:04:26,550 --> 03:04:29,510 like this select star from invoices where payment date is not now let's 8202 03:04:29,510 --> 03:04:29,520 where payment date is not now let's 8203 03:04:29,520 --> 03:04:31,860 where payment date is not now let's execute this query 8204 03:04:31,860 --> 03:04:31,870 execute this query 8205 03:04:31,870 --> 03:04:34,020 execute this query these are the two records that don't 8206 03:04:34,020 --> 03:04:34,030 these are the two records that don't 8207 03:04:34,030 --> 03:04:35,760 these are the two records that don't have a payment date so once we're 8208 03:04:35,760 --> 03:04:35,770 have a payment date so once we're 8209 03:04:35,770 --> 03:04:37,410 have a payment date so once we're confident that we're updating the right 8210 03:04:37,410 --> 03:04:37,420 confident that we're updating the right 8211 03:04:37,420 --> 03:04:41,040 confident that we're updating the right records then we come back here and get 8212 03:04:41,040 --> 03:04:41,050 records then we come back here and get 8213 03:04:41,050 --> 03:04:43,020 records then we come back here and get rid of this select statement and just 8214 03:04:43,020 --> 03:04:43,030 rid of this select statement and just 8215 03:04:43,030 --> 03:04:45,570 rid of this select statement and just attach the where clause to our update 8216 03:04:45,570 --> 03:04:45,580 attach the where clause to our update 8217 03:04:45,580 --> 03:04:47,230 attach the where clause to our update statement 8218 03:04:47,230 --> 03:04:47,240 statement 8219 03:04:47,240 --> 03:04:50,440 statement you 8220 03:04:50,440 --> 03:04:50,450 8221 03:04:50,450 --> 03:04:52,820 all right here's your exercise for this 8222 03:04:52,820 --> 03:04:52,830 all right here's your exercise for this 8223 03:04:52,830 --> 03:04:53,389 all right here's your exercise for this tutorial 8224 03:04:53,389 --> 03:04:53,399 tutorial 8225 03:04:53,399 --> 03:04:55,880 tutorial back to our sequel store database look 8226 03:04:55,880 --> 03:04:55,890 back to our sequel store database look 8227 03:04:55,890 --> 03:04:58,580 back to our sequel store database look at the orders table as you can see in 8228 03:04:58,580 --> 03:04:58,590 at the orders table as you can see in 8229 03:04:58,590 --> 03:05:01,010 at the orders table as you can see in some other orders don't have a comment I 8230 03:05:01,010 --> 03:05:01,020 some other orders don't have a comment I 8231 03:05:01,020 --> 03:05:03,320 some other orders don't have a comment I want you to write a sequel statement to 8232 03:05:03,320 --> 03:05:03,330 want you to write a sequel statement to 8233 03:05:03,330 --> 03:05:05,210 want you to write a sequel statement to update the comments for orders for 8234 03:05:05,210 --> 03:05:05,220 update the comments for orders for 8235 03:05:05,220 --> 03:05:08,210 update the comments for orders for customers will have more than 3000 8236 03:05:08,210 --> 03:05:08,220 customers will have more than 3000 8237 03:05:08,220 --> 03:05:10,370 customers will have more than 3000 points so customers who have more than 8238 03:05:10,370 --> 03:05:10,380 points so customers who have more than 8239 03:05:10,380 --> 03:05:12,679 points so customers who have more than 3000 points regard them as gold 8240 03:05:12,679 --> 03:05:12,689 3000 points regard them as gold 8241 03:05:12,689 --> 03:05:15,590 3000 points regard them as gold customers find their orders if they have 8242 03:05:15,590 --> 03:05:15,600 customers find their orders if they have 8243 03:05:15,600 --> 03:05:17,750 customers find their orders if they have placed on order update the comments 8244 03:05:17,750 --> 03:05:17,760 placed on order update the comments 8245 03:05:17,760 --> 03:05:20,150 placed on order update the comments column and set it to gold customer 8246 03:05:20,150 --> 03:05:20,160 column and set it to gold customer 8247 03:05:20,160 --> 03:05:23,110 column and set it to gold customer that's a really good exercise 8248 03:05:23,110 --> 03:05:23,120 that's a really good exercise 8249 03:05:23,120 --> 03:05:26,110 that's a really good exercise you 8250 03:05:26,110 --> 03:05:26,120 8251 03:05:26,120 --> 03:05:28,820 all right first we need to find the gold 8252 03:05:28,820 --> 03:05:28,830 all right first we need to find the gold 8253 03:05:28,830 --> 03:05:31,881 all right first we need to find the gold customers so select everything from the 8254 03:05:31,881 --> 03:05:31,891 customers so select everything from the 8255 03:05:31,891 --> 03:05:35,511 customers so select everything from the customers table where points is greater 8256 03:05:35,511 --> 03:05:35,521 customers table where points is greater 8257 03:05:35,521 --> 03:05:38,720 customers table where points is greater than 3000 and by the way because the 8258 03:05:38,720 --> 03:05:38,730 than 3000 and by the way because the 8259 03:05:38,730 --> 03:05:41,030 than 3000 and by the way because the current database is sequel invoicing we 8260 03:05:41,030 --> 03:05:41,040 current database is sequel invoicing we 8261 03:05:41,040 --> 03:05:43,160 current database is sequel invoicing we either have to type out a use statement 8262 03:05:43,160 --> 03:05:43,170 either have to type out a use statement 8263 03:05:43,170 --> 03:05:45,620 either have to type out a use statement on the top or double click this database 8264 03:05:45,620 --> 03:05:45,630 on the top or double click this database 8265 03:05:45,630 --> 03:05:49,520 on the top or double click this database before executing this query so there you 8266 03:05:49,520 --> 03:05:49,530 before executing this query so there you 8267 03:05:49,530 --> 03:05:49,850 before executing this query so there you go 8268 03:05:49,850 --> 03:05:49,860 go 8269 03:05:49,860 --> 03:05:52,551 go we have three gold customers now we need 8270 03:05:52,551 --> 03:05:52,561 we have three gold customers now we need 8271 03:05:52,561 --> 03:05:54,620 we have three gold customers now we need to get the idea of these customers to 8272 03:05:54,620 --> 03:05:54,630 to get the idea of these customers to 8273 03:05:54,630 --> 03:05:58,280 to get the idea of these customers to use them in an update statement so we 8274 03:05:58,280 --> 03:05:58,290 use them in an update statement so we 8275 03:05:58,290 --> 03:06:02,570 use them in an update statement so we only select customer ID here and then 8276 03:06:02,570 --> 03:06:02,580 only select customer ID here and then 8277 03:06:02,580 --> 03:06:04,730 only select customer ID here and then use this select statement as a sub-query 8278 03:06:04,730 --> 03:06:04,740 use this select statement as a sub-query 8279 03:06:04,740 --> 03:06:09,790 use this select statement as a sub-query and an update statement so update orders 8280 03:06:09,790 --> 03:06:09,800 and an update statement so update orders 8281 03:06:09,800 --> 03:06:15,850 and an update statement so update orders set comments to gold customer where 8282 03:06:15,850 --> 03:06:15,860 set comments to gold customer where 8283 03:06:15,860 --> 03:06:18,921 set comments to gold customer where customer ID because we're dealing with 8284 03:06:18,921 --> 03:06:18,931 customer ID because we're dealing with 8285 03:06:18,931 --> 03:06:21,500 customer ID because we're dealing with multiple customer IDs we need to use the 8286 03:06:21,500 --> 03:06:21,510 multiple customer IDs we need to use the 8287 03:06:21,510 --> 03:06:24,591 multiple customer IDs we need to use the in operator and then to use this as a 8288 03:06:24,591 --> 03:06:24,601 in operator and then to use this as a 8289 03:06:24,601 --> 03:06:26,450 in operator and then to use this as a sub-query we need to enclose it in 8290 03:06:26,450 --> 03:06:26,460 sub-query we need to enclose it in 8291 03:06:26,460 --> 03:06:29,780 sub-query we need to enclose it in parentheses that's it let's indent the 8292 03:06:29,780 --> 03:06:29,790 parentheses that's it let's indent the 8293 03:06:29,790 --> 03:06:32,750 parentheses that's it let's indent the code that's better so here's the final 8294 03:06:32,750 --> 03:06:32,760 code that's better so here's the final 8295 03:06:32,760 --> 03:06:39,210 code that's better so here's the final solution 8296 03:06:39,210 --> 03:06:39,220 8297 03:06:39,220 --> 03:06:41,530 so you have learn how to insert an 8298 03:06:41,530 --> 03:06:41,540 so you have learn how to insert an 8299 03:06:41,540 --> 03:06:43,510 so you have learn how to insert an update data in this lecture we're gonna 8300 03:06:43,510 --> 03:06:43,520 update data in this lecture we're gonna 8301 03:06:43,520 --> 03:06:45,400 update data in this lecture we're gonna finish this section by learning how to 8302 03:06:45,400 --> 03:06:45,410 finish this section by learning how to 8303 03:06:45,410 --> 03:06:47,979 finish this section by learning how to delete data that is very easy we use the 8304 03:06:47,979 --> 03:06:47,989 delete data that is very easy we use the 8305 03:06:47,989 --> 03:06:50,950 delete data that is very easy we use the delete from statement to delete records 8306 03:06:50,950 --> 03:06:50,960 delete from statement to delete records 8307 03:06:50,960 --> 03:06:53,679 delete from statement to delete records from a table let's say the invoices 8308 03:06:53,679 --> 03:06:53,689 from a table let's say the invoices 8309 03:06:53,689 --> 03:06:56,650 from a table let's say the invoices table now optionally we can add a search 8310 03:06:56,650 --> 03:06:56,660 table now optionally we can add a search 8311 03:06:56,660 --> 03:06:58,780 table now optionally we can add a search condition to identify the records we 8312 03:06:58,780 --> 03:06:58,790 condition to identify the records we 8313 03:06:58,790 --> 03:07:00,639 condition to identify the records we want to delete if you don't write this 8314 03:07:00,639 --> 03:07:00,649 want to delete if you don't write this 8315 03:07:00,649 --> 03:07:02,469 want to delete if you don't write this where clause with this statement will 8316 03:07:02,469 --> 03:07:02,479 where clause with this statement will 8317 03:07:02,479 --> 03:07:04,690 where clause with this statement will delete all the records in this table and 8318 03:07:04,690 --> 03:07:04,700 delete all the records in this table and 8319 03:07:04,700 --> 03:07:06,849 delete all the records in this table and obviously that's very dangerous so be 8320 03:07:06,849 --> 03:07:06,859 obviously that's very dangerous so be 8321 03:07:06,859 --> 03:07:08,469 obviously that's very dangerous so be very careful when executing the 8322 03:07:08,469 --> 03:07:08,479 very careful when executing the 8323 03:07:08,479 --> 03:07:10,599 very careful when executing the statement now here let's say we want to 8324 03:07:10,599 --> 03:07:10,609 statement now here let's say we want to 8325 03:07:10,609 --> 03:07:13,479 statement now here let's say we want to delete the invoice with the ID one so 8326 03:07:13,479 --> 03:07:13,489 delete the invoice with the ID one so 8327 03:07:13,489 --> 03:07:16,570 delete the invoice with the ID one so where invoice ID it goes to one now here 8328 03:07:16,570 --> 03:07:16,580 where invoice ID it goes to one now here 8329 03:07:16,580 --> 03:07:18,969 where invoice ID it goes to one now here we can also use sub-queries let's say we 8330 03:07:18,969 --> 03:07:18,979 we can also use sub-queries let's say we 8331 03:07:18,979 --> 03:07:20,860 we can also use sub-queries let's say we want to delete all the invoices for the 8332 03:07:20,860 --> 03:07:20,870 want to delete all the invoices for the 8333 03:07:20,870 --> 03:07:24,309 want to delete all the invoices for the client called my works first let's find 8334 03:07:24,309 --> 03:07:24,319 client called my works first let's find 8335 03:07:24,319 --> 03:07:27,190 client called my works first let's find this client so select everything from 8336 03:07:27,190 --> 03:07:27,200 this client so select everything from 8337 03:07:27,200 --> 03:07:30,849 this client so select everything from the clients table where name equals to 8338 03:07:30,849 --> 03:07:30,859 the clients table where name equals to 8339 03:07:30,859 --> 03:07:35,610 the clients table where name equals to my works let's execute the second query 8340 03:07:35,610 --> 03:07:35,620 my works let's execute the second query 8341 03:07:35,620 --> 03:07:40,000 my works let's execute the second query so here's our client now we can get this 8342 03:07:40,000 --> 03:07:40,010 so here's our client now we can get this 8343 03:07:40,010 --> 03:07:41,740 so here's our client now we can get this client ID and use it in our search 8344 03:07:41,740 --> 03:07:41,750 client ID and use it in our search 8345 03:07:41,750 --> 03:07:46,719 client ID and use it in our search condition so where client ID equals two 8346 03:07:46,719 --> 03:07:46,729 condition so where client ID equals two 8347 03:07:46,729 --> 03:07:50,530 condition so where client ID equals two this is where we add our sub query there 8348 03:07:50,530 --> 03:07:50,540 this is where we add our sub query there 8349 03:07:50,540 --> 03:07:51,610 this is where we add our sub query there you go 8350 03:07:51,610 --> 03:07:51,620 you go 8351 03:07:51,620 --> 03:07:55,300 you go just like before beautiful so this is 8352 03:07:55,300 --> 03:07:55,310 just like before beautiful so this is 8353 03:07:55,310 --> 03:08:03,621 just like before beautiful so this is how we can delete data in sequel 8354 03:08:03,621 --> 03:08:03,631 8355 03:08:03,631 --> 03:08:05,461 all right we're done with this section 8356 03:08:05,461 --> 03:08:05,471 all right we're done with this section 8357 03:08:05,471 --> 03:08:07,680 all right we're done with this section but before going to the next section I 8358 03:08:07,680 --> 03:08:07,690 but before going to the next section I 8359 03:08:07,690 --> 03:08:09,720 but before going to the next section I want you to restore all these databases 8360 03:08:09,720 --> 03:08:09,730 want you to restore all these databases 8361 03:08:09,730 --> 03:08:11,970 want you to restore all these databases to their original state because in this 8362 03:08:11,970 --> 03:08:11,980 to their original state because in this 8363 03:08:11,980 --> 03:08:14,311 to their original state because in this section we added some data we updated 8364 03:08:14,311 --> 03:08:14,321 section we added some data we updated 8365 03:08:14,321 --> 03:08:16,501 section we added some data we updated some data with deleted some records so 8366 03:08:16,501 --> 03:08:16,511 some data with deleted some records so 8367 03:08:16,511 --> 03:08:18,390 some data with deleted some records so if you don't restore these databases you 8368 03:08:18,390 --> 03:08:18,400 if you don't restore these databases you 8369 03:08:18,400 --> 03:08:20,041 if you don't restore these databases you might see different results going 8370 03:08:20,041 --> 03:08:20,051 might see different results going 8371 03:08:20,051 --> 03:08:22,801 might see different results going forward so restoring these databases is 8372 03:08:22,801 --> 03:08:22,811 forward so restoring these databases is 8373 03:08:22,811 --> 03:08:25,531 forward so restoring these databases is pretty easy here in MySQL workbench on 8374 03:08:25,531 --> 03:08:25,541 pretty easy here in MySQL workbench on 8375 03:08:25,541 --> 03:08:28,761 pretty easy here in MySQL workbench on the top go to the file menu and open 8376 03:08:28,761 --> 03:08:28,771 the top go to the file menu and open 8377 03:08:28,771 --> 03:08:32,161 the top go to the file menu and open sequel script then navigate to the 8378 03:08:32,161 --> 03:08:32,171 sequel script then navigate to the 8379 03:08:32,171 --> 03:08:34,261 sequel script then navigate to the directory where you stored the sequel 8380 03:08:34,261 --> 03:08:34,271 directory where you stored the sequel 8381 03:08:34,271 --> 03:08:36,271 directory where you stored the sequel scripts for this course in case you lost 8382 03:08:36,271 --> 03:08:36,281 scripts for this course in case you lost 8383 03:08:36,281 --> 03:08:38,041 scripts for this course in case you lost that directory go back to the first 8384 03:08:38,041 --> 03:08:38,051 that directory go back to the first 8385 03:08:38,051 --> 03:08:39,661 that directory go back to the first section we have a lecture for 8386 03:08:39,661 --> 03:08:39,671 section we have a lecture for 8387 03:08:39,671 --> 03:08:41,331 section we have a lecture for downloading the supplementary materials 8388 03:08:41,331 --> 03:08:41,341 downloading the supplementary materials 8389 03:08:41,341 --> 03:08:44,851 downloading the supplementary materials so in this directory open create 8390 03:08:44,851 --> 03:08:44,861 so in this directory open create 8391 03:08:44,861 --> 03:08:49,441 so in this directory open create databases sequel now execute this script 8392 03:08:49,441 --> 03:08:49,451 databases sequel now execute this script 8393 03:08:49,451 --> 03:08:52,081 databases sequel now execute this script to recreate all of our databases all 8394 03:08:52,081 --> 03:08:52,091 to recreate all of our databases all 8395 03:08:52,091 --> 03:08:53,371 to recreate all of our databases all right beautiful 8396 03:08:53,371 --> 03:08:53,381 right beautiful 8397 03:08:53,381 --> 03:08:55,321 right beautiful now let's open up the navigator panel 8398 03:08:55,321 --> 03:08:55,331 now let's open up the navigator panel 8399 03:08:55,331 --> 03:08:57,331 now let's open up the navigator panel you can see the databases disappeared 8400 03:08:57,331 --> 03:08:57,341 you can see the databases disappeared 8401 03:08:57,341 --> 03:08:59,191 you can see the databases disappeared from here simply click on this refresh 8402 03:08:59,191 --> 03:08:59,201 from here simply click on this refresh 8403 03:08:59,201 --> 03:09:02,701 from here simply click on this refresh icon beautiful all right we're done with 8404 03:09:02,701 --> 03:09:02,711 icon beautiful all right we're done with 8405 03:09:02,711 --> 03:09:04,231 icon beautiful all right we're done with this section I will see you in the next 8406 03:09:04,231 --> 03:09:04,241 this section I will see you in the next 8407 03:09:04,241 --> 03:09:06,210 this section I will see you in the next section 8408 03:09:06,210 --> 03:09:06,220 section 8409 03:09:06,220 --> 03:09:09,220 section hey guys maash here in case you haven't 8410 03:09:09,220 --> 03:09:09,230 hey guys maash here in case you haven't 8411 03:09:09,230 --> 03:09:11,620 hey guys maash here in case you haven't seen my website yet head over to code 8412 03:09:11,620 --> 03:09:11,630 seen my website yet head over to code 8413 03:09:11,630 --> 03:09:14,350 seen my website yet head over to code with mass comm this is my coding school 8414 03:09:14,350 --> 03:09:14,360 with mass comm this is my coding school 8415 03:09:14,360 --> 03:09:16,600 with mass comm this is my coding school where you can find plenty of courses on 8416 03:09:16,600 --> 03:09:16,610 where you can find plenty of courses on 8417 03:09:16,610 --> 03:09:18,420 where you can find plenty of courses on web and mobile application development 8418 03:09:18,420 --> 03:09:18,430 web and mobile application development 8419 03:09:18,430 --> 03:09:21,610 web and mobile application development in fact recently I published a complete 8420 03:09:21,610 --> 03:09:21,620 in fact recently I published a complete 8421 03:09:21,620 --> 03:09:24,100 in fact recently I published a complete sequel course that is about ten hours 8422 03:09:24,100 --> 03:09:24,110 sequel course that is about ten hours 8423 03:09:24,110 --> 03:09:26,020 sequel course that is about ten hours long and it teaches you everything you 8424 03:09:26,020 --> 03:09:26,030 long and it teaches you everything you 8425 03:09:26,030 --> 03:09:27,460 long and it teaches you everything you need to know from the basic to the 8426 03:09:27,460 --> 03:09:27,470 need to know from the basic to the 8427 03:09:27,470 --> 03:09:29,680 need to know from the basic to the advanced topics such as database design 8428 03:09:29,680 --> 03:09:29,690 advanced topics such as database design 8429 03:09:29,690 --> 03:09:32,520 advanced topics such as database design security writing complex queries 8430 03:09:32,520 --> 03:09:32,530 security writing complex queries 8431 03:09:32,530 --> 03:09:35,051 security writing complex queries transactions events and much much more 8432 03:09:35,051 --> 03:09:35,061 transactions events and much much more 8433 03:09:35,061 --> 03:09:37,630 transactions events and much much more these are the topics that every software 8434 03:09:37,630 --> 03:09:37,640 these are the topics that every software 8435 03:09:37,640 --> 03:09:40,630 these are the topics that every software engineer must master this YouTube course 8436 03:09:40,630 --> 03:09:40,640 engineer must master this YouTube course 8437 03:09:40,640 --> 03:09:42,640 engineer must master this YouTube course you've been watching is the first three 8438 03:09:42,640 --> 03:09:42,650 you've been watching is the first three 8439 03:09:42,650 --> 03:09:45,160 you've been watching is the first three hours of my complete sequel course that 8440 03:09:45,160 --> 03:09:45,170 hours of my complete sequel course that 8441 03:09:45,170 --> 03:09:47,440 hours of my complete sequel course that is about ten hours long so if you want 8442 03:09:47,440 --> 03:09:47,450 is about ten hours long so if you want 8443 03:09:47,450 --> 03:09:50,110 is about ten hours long so if you want to master sequel and get job ready I 8444 03:09:50,110 --> 03:09:50,120 to master sequel and get job ready I 8445 03:09:50,120 --> 03:09:51,880 to master sequel and get job ready I highly encourage you to enroll in my 8446 03:09:51,880 --> 03:09:51,890 highly encourage you to enroll in my 8447 03:09:51,890 --> 03:09:54,130 highly encourage you to enroll in my complete sequel course you can watch it 8448 03:09:54,130 --> 03:09:54,140 complete sequel course you can watch it 8449 03:09:54,140 --> 03:09:56,710 complete sequel course you can watch it anytime anywhere as many times as you 8450 03:09:56,710 --> 03:09:56,720 anytime anywhere as many times as you 8451 03:09:56,720 --> 03:09:59,020 anytime anywhere as many times as you want you can watch it online or download 8452 03:09:59,020 --> 03:09:59,030 want you can watch it online or download 8453 03:09:59,030 --> 03:10:00,790 want you can watch it online or download the videos the course comes with a 8454 03:10:00,790 --> 03:10:00,800 the videos the course comes with a 8455 03:10:00,800 --> 03:10:03,100 the videos the course comes with a 30-day money-back guarantee and a 8456 03:10:03,100 --> 03:10:03,110 30-day money-back guarantee and a 8457 03:10:03,110 --> 03:10:04,870 30-day money-back guarantee and a certificate of completion that you can 8458 03:10:04,870 --> 03:10:04,880 certificate of completion that you can 8459 03:10:04,880 --> 03:10:07,150 certificate of completion that you can add to your resume the price for this 8460 03:10:07,150 --> 03:10:07,160 add to your resume the price for this 8461 03:10:07,160 --> 03:10:08,740 add to your resume the price for this course is one hundred and forty nine 8462 03:10:08,740 --> 03:10:08,750 course is one hundred and forty nine 8463 03:10:08,750 --> 03:10:11,350 course is one hundred and forty nine dollars but the first 200 students can 8464 03:10:11,350 --> 03:10:11,360 dollars but the first 200 students can 8465 03:10:11,360 --> 03:10:13,990 dollars but the first 200 students can get it for just over ten dollars so if 8466 03:10:13,990 --> 03:10:14,000 get it for just over ten dollars so if 8467 03:10:14,000 --> 03:10:15,880 get it for just over ten dollars so if you're interested the link is below this 8468 03:10:15,880 --> 03:10:15,890 you're interested the link is below this 8469 03:10:15,890 --> 03:10:18,101 you're interested the link is below this video