We use cookies to enhance your experience on the site
CodeWorlds

Scriptorium mastered - summary

Wonderful, @name! You are leaving the Scriptorium a true master of filtering. You can now point the Library to exactly the scrolls you need - not a single one more.

What you have learned

  • WHERE selects only the rows that satisfy a condition (always after
    FROM
    ).
  • Comparison operators:
    =
    ,
    <>
    ,
    <
    ,
    >
    ,
    <=
    ,
    >=
    .
  • We wrap text in single quotes
    ' '
    , but not numbers.
  • AND - all conditions at once; OR - one is enough; NOT - negation.
  • Parentheses
    ( )
    order things when we mix
    AND
    and
    OR
    .
  • IN (...) - a list of allowed values (a shorter way of writing many
    OR
    ).
  • BETWEEN a AND b - a range together with both ends.
  • LIKE with the characters
    %
    (any sequence) and
    _
    (one character);
    NOT LIKE
    is the negation.
  • IS NULL / IS NOT NULL - checking for emptiness (never
    = NULL
    !).

An example tying it all together

1SELECT * FROM ksiazki
2WHERE cena BETWEEN 20 AND 80
3  AND kategoria_id IN (1, 2)
4  AND tytul LIKE 'O%';

This query will return books priced from 20 to 80 coins, from category 1 or 2, whose title starts with O. Three conditions in one - the full power of the Scriptorium!

What's next?

In the next location you will learn to order results (

ORDER BY
) and limit their number (
LIMIT
), so that from the filtered pile of scrolls you can pick the most important ones. You already have the filter - now it is time to give it order. Onward, deeper into the Library, @name!

Go to CodeWorlds