Searching Tables
Speaking of searching tables, how do we do that? We use and reintroduce the where clause. The where clause can take a myriad of conditions and filter the table down to only what you need, instead of getting back the entire table.
For example:
select * from names where lastName = 'Smith';
How do we search the database using joins?
mysql> select n.lastName, a.zip from names n, addresses a where n.id = a.nameId and lastName = 'Smith';
+----------+-------+
| lastName | zip |
+----------+-------+
| Smith | 90000 |
| Smith | 90001 |
+----------+-------+
2 rows in set (0.00 sec)
We basically put an and in there between n.id=a.nameId and lastName='Smith'
How do we search the database using left joins?
mysql> select n.lastName, a.zip from names n left join addresses a on n.id = a.nameId where lastName = 'Smith';
+----------+-------+
| lastName | zip |
+----------+-------+
| Smith | 90000 |
| Smith | 90001 |
+----------+-------+
2 rows in set (0.00 sec)