Now in the last lesson we looked at how we would create new tables using the SQL language and how 1
we would insert data into our tables. In this lesson 2
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
Well the most often used keyword is the SQL SELECT keyword. 4
And what this does is it allows you to read the data from your database. 5
So for example whenever I right clicked on my tables and I clicked on show table you can see up here 6
this syntax show up automatically because I'm able to show the table by running this statement. And what 7
it says is SELECT * FROM products. Products is the table that I want to see and * stands for a 8
wildcard. 9
So it means select everything from the products table 10
and this is why we see everything in our table. 11
Now if you only wanted one column or two columns from this table then instead of asterix or * you 12
can simply write SELECT name, price FROM this products table. And if you hit run you can see we've 13
now removed that id column and we're reading from our database only the columns that we want. 14
Now what if you only wanted a particular row from your database? 15
Say for example you only wanted to see the first row, 16
the one with an id of one. 17
How would you do that with SQL? Well this is when you would need to search through your database by 18
using the WHERE keyword. 19
So this is the syntax we would SELECT a particular column or if you want to select all of the columns 20
then you would put in asterisks and then we specify the table that you want to read the data from 21
and then the WHERE is a search condition. 22
So you could say something like 23
WHERE country equals Mexico or WHERE custom ID equals one. 24
If we tried out in the browser we can write SELECT everything which is * FROM the products table 25
where id equals 1. 26
So now if I hit run it isolates that single record where the id is equal to 1 and we select a single 27
row. 28
Now if you read the documentation you can see that there's other operators where you can get fancier 29
than what we've done. 30
So you can use things such as equal or greater or less than between like in all sorts of things 31
to modify this WHERE statement so that you can select the pieces of data that you need. 32
So this statement is for reading data from your database and grabbing the data that meet certain criteria. 33
And you'll see the statement a lot 34
when you start working with SQL databases.