WEBVTT 0 00:00.300 --> 00:06.570 Now in the last lesson we looked at how we would create new tables using the SQL language and how 1 00:06.570 --> 00:10.790 we would insert data into our tables. In this lesson 2 00:10.800 --> 00:18.270 we're going to look at the next part of CRUD which is 'R' for read. How would you read data in your table? 3 00:19.100 --> 00:24.390 Well the most often used keyword is the SQL SELECT keyword. 4 00:24.680 --> 00:29.800 And what this does is it allows you to read the data from your database. 5 00:29.810 --> 00:37.220 So for example whenever I right clicked on my tables and I clicked on show table you can see up here 6 00:37.310 --> 00:44.660 this syntax show up automatically because I'm able to show the table by running this statement. And what 7 00:44.660 --> 00:53.780 it says is SELECT * FROM products. Products is the table that I want to see and * stands for a 8 00:53.780 --> 00:54.530 wildcard. 9 00:54.530 --> 00:58.650 So it means select everything from the products table 10 00:58.850 --> 01:02.900 and this is why we see everything in our table. 11 01:02.900 --> 01:10.100 Now if you only wanted one column or two columns from this table then instead of asterix or * you 12 01:10.100 --> 01:19.370 can simply write SELECT name, price FROM this products table. And if you hit run you can see we've 13 01:19.370 --> 01:26.330 now removed that id column and we're reading from our database only the columns that we want. 14 01:26.360 --> 01:31.160 Now what if you only wanted a particular row from your database? 15 01:31.160 --> 01:35.160 Say for example you only wanted to see the first row, 16 01:35.230 --> 01:37.900 the one with an id of one. 17 01:37.940 --> 01:45.300 How would you do that with SQL? Well this is when you would need to search through your database by 18 01:45.300 --> 01:47.620 using the WHERE keyword. 19 01:47.640 --> 01:54.720 So this is the syntax we would SELECT a particular column or if you want to select all of the columns 20 01:55.050 --> 02:00.750 then you would put in asterisks and then we specify the table that you want to read the data from 21 02:01.020 --> 02:04.030 and then the WHERE is a search condition. 22 02:04.080 --> 02:06.200 So you could say something like 23 02:06.230 --> 02:11.690 WHERE country equals Mexico or WHERE custom ID equals one. 24 02:11.820 --> 02:22.870 If we tried out in the browser we can write SELECT everything which is * FROM the products table 25 02:23.960 --> 02:28.520 where id equals 1. 26 02:28.520 --> 02:36.590 So now if I hit run it isolates that single record where the id is equal to 1 and we select a single 27 02:36.670 --> 02:38.380 row. 28 02:38.380 --> 02:44.050 Now if you read the documentation you can see that there's other operators where you can get fancier 29 02:44.200 --> 02:45.450 than what we've done. 30 02:45.640 --> 02:52.040 So you can use things such as equal or greater or less than between like in all sorts of things 31 02:52.060 --> 02:57.930 to modify this WHERE statement so that you can select the pieces of data that you need. 32 02:58.330 --> 03:05.890 So this statement is for reading data from your database and grabbing the data that meet certain criteria. 33 03:06.490 --> 03:08.050 And you'll see the statement a lot 34 03:08.050 --> 03:10.110 when you start working with SQL databases.