Before we reach for the hardest tricks, let us return to the fundamentals. Every great query begins with three simple tools: selection, filter and order.
SELECT names the columns, and FROM names the shelf we read from:1SELECT tytul, cena FROM ksiazki;WHERE lets through only the rows that meet a condition. We can use the operators =, >, <, >=, <=, <>:1SELECT tytul, cena FROM ksiazki WHERE dostepna = 1;This question returns only books that are on the shelf.
ORDER BY arranges results by a chosen column. ASC is ascending order (the default), DESC is descending:1SELECT tytul, cena FROM ksiazki ORDER BY cena DESC;LIMIT restricts the number of returned rows. Together with sorting it produces rankings:1SELECT tytul, cena FROM ksiazki ORDER BY cena DESC LIMIT 3;This query shows the three most expensive books in the Library. Filter, order and limit - the everyday tools of every scribe!