Database Reference
In-Depth Information
Limiting Results
The birds table has nearly 30,000 rows, so selecting data without limits can return more
rows than you might want to view at a time. We've already used the LIMIT clause to re-
solve this problem. We limited the results of the SELECT statement to three rows, the first
three rows based on the WHERE and ORDER BY clauses. If we'd like to see the subsequent
rows, maybe the next two based on the criteria we gave previously, we could change the
LIMIT clause to show five rows. But an alternative, which is often a better choice, is to do
something like this:
SELECT common_name, scientific_name, family_id
FROM birds
WHERE family_id IN(103, 160, 162, 164)
AND common_name != ''
ORDER BY common_name
LIMIT 3, 2;
+------------------------+-------------------------+-----------+
| common_name | scientific_name | family_id |
+------------------------+-------------------------+-----------+
| American Avocet | Recurvirostra americana | 162 |
| American Golden-Plover | Pluvialis dominica | 103 |
+------------------------+-------------------------+-----------+
This LIMIT clause has two values: the point where we want the results to begin, then the
number of rows to display. The result is to show rows 3 and 4. Incidentally, LIMIT 3 used
previously is the same as LIMIT 0, 3 : the 0 tells MySQL not to skipany rows.
Search WWH ::




Custom Search