Database DesignSQL basicsLesson 26 / 69

SELECT, WHERE & ORDER BY

Code Lab30 min

SELECT, WHERE & ORDER BY

Reading is one verb with three clauses:

SELECT name, price FROM books
WHERE price < 20 AND author_id = 1
ORDER BY price DESC;
  • SELECT picks columns.
  • WHERE filters rows — every condition is a question about a row.
  • ORDER BY sorts the result.

Add LIMIT 5 for the top five, and remember: WHERE runs before the result exists, so it cannot use column aliases from SELECT. Small language, sharp edges — worth knowing early.

Exercise

From your books table: the three cheapest books by author 1, most expensive first, showing title and price only.

Practice this lesson in the IDE

Open the Database Design practice workspace, edit the starter code, and run your work in the browser.

Open IDE and practice