>_ IzzyLab

Topic breakdown

Without sorting, the database returns rows in whatever order is convenient for it. The order is set by ORDER BY:

SELECT title, year FROM books ORDER BY year;        -- oldest to newest
SELECT title, year FROM books ORDER BY year DESC;   -- newest to oldest
SELECT title FROM books ORDER BY title LIMIT 5;     -- the first five alphabetically

ASC (ascending) is the default order, you don't have to write it; DESC is descending. LIMIT n keeps only the first n rows of the result.

The parts of a query go in a strict order: SELECT … FROM … WHERE … ORDER BY … LIMIT …. You can also sort by a column that isn't in SELECT.

What's checked

  1. File /root/top3.txt created
  2. The file has exactly three lines
  3. The file holds the three most expensive products
  4. Products go from the most expensive

What it looks like