Database Reference
In-Depth Information
Sandpipers (e.g., Scolopacidae ). First, we need the family_id for each of these famil-
ies. Execute the following on your server:
SELECT * FROM bird_families
WHERE scientific_name
IN('Charadriidae','Haematopodidae','Recurvirostridae','Scolopacidae');
+-----------+------------------+------------------------------+----------+
| family_id | scientific_name | brief_description |
order_id |
+-----------+------------------+------------------------------+----------+
| 103 | Charadriidae | Plovers, Dotterels, Lapwings |
102 |
| 160 | Haematopodidae | Oystercatchers |
102 |
| 162 | Recurvirostridae | Stilts and Avocets |
102 |
| 164 | Scolopacidae | Sandpipers and Allies |
102 |
+-----------+------------------+------------------------------+----------+
In this SELECT statement, we added another item to the WHERE clause,the IN operator.
It lists, within parentheses, the various values we want in the scientific_name
column. Let's use the IN operator again to get a list of birds and also test the LIMIT
clause:
SELECT common_name, scientific_name, family_id
FROM birds
WHERE family_id IN(103, 160, 162, 164)
ORDER BY common_name
LIMIT 3;
+-------------+--------------------------------+-----------+
| common_name | scientific_name | family_id |
+-------------+--------------------------------+-----------+
| | Charadrius obscurus aquilonius | 103 |
| | Numenius phaeopus phaeopus | 164 |
| | Tringa totanus eurhinus | 164 |
+-------------+--------------------------------+-----------+
Notice that we didn't put the numeric values in quotes as we did with the family names in
the previous SQL statement. Single or double quotes are necessary for strings, but they're
optional for numeric values. However, it's a better practice to not use quotes around nu-
meric values. They can affect performance and cause incorrect results if you mix them
with strings.
Search WWH ::




Custom Search