Chapter 4. Retrieving Data: Simple Queries

This Chapter covers the basic phrases needed to survive your first few days with MySQL. Phrases for some of the most common tasks, such as sorting data or finding text that matches a particular pattern, are provided, and finding your way out of a few major pitfalls, such as the mysterious and perplexing NULL, is discussed.

For more advanced queries, including joins and subqueries, see Chapter 9,“Advanced Queries.”

Limiting the Number of Rows Returned

# Use the LIMIT clause to fetch the first two rows
SELECT author FROM book LIMIT 2;

# ... or starting from the second row, fetch two
# rows
SELECT author FROM book LIMIT 1, 2;

The LIMIT clause is used to fetch a limited subset of rows from a query. The clause ...

Get MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.