Let's take the next step in controlling the output of SELECT. In the
previous section, we showed how to select only certain columns from the table.
Now, we will show how to select only certain rows. The additional thing needed
to do this is the WHERE clause. Without a WHERE clause, every
row is returned.
The WHERE clause goes right after the FROM clause. In the
WHERE clause, you specify the rows you want returned. For example,
see figure .
My first WHERE
The query requests to return the rows that have an age column equal
to 23. Figure
More complex WHERE clause
shows a more complex example that returns two rows. You can combine the column
restrictions and the row restrictions in a single query, allowing you to select
any single cell, or a block of cells. See figures
A single cell
A block of cells
Try using one of the other columns in the WHERE clause. Up to this
point, we have made only comparisons on the age column. The age
column is integer. The only tricky part about the other columns that
they are char() columns, so you have to put the comparison value in single
quotes. You also have to match the capitalization exactly. See figure .
If you compared the firstname column to 'SAM' or 'sam',
it would have returned no rows.