The where clause is very similar to an if statement in any language. You can get pretty complicated with it, including using parentheses. The normal math order of operations applies here. For example, * will always happen before +, etc. You can also use or in your queries.
Lets insert another addresses record, still pointing to Jim Smith:
insert into addresses set nameId=1, street="4576 Better St", city="Los Angeles", state="CA", zip="90002";
This gives us:
mysql> select * from addresses;
+----+--------+----------------+-------------+-------+-------+
| id | nameId | street | city | state | zip |
+----+--------+----------------+-------------+-------+-------+
| 1 | 1 | 1234 Main St | Los Angeles | CA | 90000 |
| 2 | 1 | 4321 Good St | Los Angeles | CA | 90001 |
| 3 | 1 | 4576 Better St | Los Angeles | CA | 90002 |
+----+--------+----------------+-------------+-------+-------+
3 rows in set (0.00 sec)
Our next query, we only want two zip codes. 90000 and 90001.
Here are a few ways to do that:
mysql> select n.lastName, a.zip from names n, addresses a where n.id=a.nameId and (zip="90000" or zip="90001");
+----------+-------+
| lastName | zip |
+----------+-------+
| Smith | 90000 |
| Smith | 90001 |
+----------+-------+
2 rows in set (0.00 sec)
In this query, we're doing all the normal things, except we've also added and (zip="90000" or zip="90001") after our join condition. What happens is if zip equals 90000 or if zip equals 90000, then return the row. Since we have two rows where this condition is met, we get those two rows back from our query. Pretty awesome!
And introducing the in where clause. You can also do the same thing we did above, but with less typing and probably more efficiency using the in condition operator.
mysql> select n.lastName, a.zip from names n, addresses a where n.id=a.nameId and zip in ("90000", "90001");
+----------+-------+
| lastName | zip |
+----------+-------+
| Smith | 90000 |
| Smith | 90001 |
+----------+-------+
2 rows in set (0.00 sec)
The in keyword basically lets you use an array of values to query. So, if 90000 or 90001 are in zip, then return a row. Since we're using parentheses around our zip condition, those operations happen first. It will match anything within the range of zips we've mentioned.
How do we do the same thing with left join?
mysql> select n.lastName, a.zip from names n left join addresses a on n.id=a.nameId where zip="90000" or zip="90001";
+----------+-------+
| lastName | zip |
+----------+-------+
| Smith | 90000 |
| Smith | 90001 |
+----------+-------+
2 rows in set (0.01 sec)
mysql> select n.lastName, a.zip from names n left join addresses a on n.id=a.nameId where zip in ("90000", "90001");
+----------+-------+
| lastName | zip |
+----------+-------+
| Smith | 90000 |
| Smith | 90001 |
+----------+-------+
2 rows in set (0.00 sec)