We use cookies to enhance your experience on the site
CodeWorlds

All together - building a report

You have now mastered every art of the catalog scribe. It is time to bring them together into one - a true library report that selects, names, sorts and limits.

The full order of clauses

Every extended query follows a fixed rhythm:

1SELECT tytul AS Tytul, cena AS Cena
2FROM ksiazki
3ORDER BY cena DESC
4LIMIT 3;

Read it like this: "Select the title and price (with pretty headers), from the shelf of books, arrange from the most expensive and show only three". The clauses always go in the order SELECT → FROM → ORDER BY → LIMIT.

Combining the arts

Nothing stops you from mixing several techniques in a single scroll:

1SELECT DISTINCT kraj
2FROM autorzy
3ORDER BY kraj ASC;

Here

DISTINCT
removes the repetitions, and
ORDER BY
lines up the unique countries alphabetically.

And here is a ranking report with an alias, sorting and a limit:

1SELECT tytul, cena AS Cena
2FROM ksiazki
3ORDER BY cena ASC
4LIMIT 5;

"Five cheapest books, with the price under a pretty header".

The scribe's advice

Build the query in layers: first choose the columns, then point to the shelf, add the sorting, and finally limit the count. That is how clear, precise reports are made, @name. Now try it yourself!

Go to CodeWorlds