Sometimes you do not want the whole shelf - only the first few scrolls. That is what LIMIT is for.
1SELECT tytul FROM ksiazki LIMIT 5;This returns the first five books. Combined with ORDER BY, true rankings are born:
1SELECT tytul, cena
2FROM ksiazki
3ORDER BY cena DESC
4LIMIT 3;This query shows the three most expensive books - we sort descending by price and take only the first three scrolls.
Remember the sacred order: SELECT → FROM → ORDER BY → LIMIT. LIMIT always goes at the very end of the query, after the sorting.
1SELECT imie, nazwisko
2FROM czytelnicy
3ORDER BY nazwisko ASC
4LIMIT 10;LIMIT is the scribe's hand that stops the stream of scrolls once the requested number is counted. In the next lesson we will add
OFFSET to it and learn to paginate.