We use cookies to enhance your experience on the site
CodeWorlds

The Catalog Hall - summary

Well done, @name! You leave the Catalog Hall a true scribe. Your queries no longer merely fetch data - they shape it.

What you have learned

  • Choosing columns - take only the fields you need instead of
    *
    . the order on the SELECT list decides the order in the result.
  • Aliases (AS) -
    SELECT tytul AS Tytul
    gives a field a pretty label in the answer.
  • DISTINCT -
    SELECT DISTINCT kraj FROM autorzy
    returns only unique values.
  • ORDER BY -
    ASC
    (ascending, the default) and
    DESC
    (descending); you can sort by several fields:
    ORDER BY rok_wydania DESC, tytul ASC
    .
  • LIMIT and OFFSET -
    LIMIT 5
    takes five rows;
    LIMIT 5 OFFSET 10
    paginates results.

A masterful spell

Everything together in a single scroll:

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

"Show the three most expensive books, with pretty headers Tytul and Cena". Beautiful, is it not?

What's next?

In the next location you will learn to filter scrolls with the

WHERE
clause - to pick only those that meet a condition (e.g. books cheaper than 50, or published after the year 2000). The catalog is ready; it is time to learn to search with precision. Forward!

Go to CodeWorlds