Often one condition is not enough. The scribe wants scrolls that are at the same time new and available, or authors from Poland or from Greece. To combine conditions we use three words: AND, OR and NOT.
The AND operator requires that all the joined conditions be satisfied:
1SELECT * FROM ksiazki
2WHERE rok_wydania > 1900 AND dostepna = 1;This means: "Books published after 1900 AND available at the same time". A row enters the result only when both conditions are true.
The OR operator requires that at least one of the conditions be satisfied:
1SELECT * FROM autorzy
2WHERE kraj = 'Polska' OR kraj = 'Grecja';This means: "Authors from Poland OR from Greece". It is enough that at least one condition is true.
The NOT operator reverses a condition - it returns what does NOT satisfy it:
1SELECT * FROM ksiazki
2WHERE NOT dostepna = 1;This means: "Books that are NOT available".
When we mix
AND and OR, use parentheses ( ) to state the order clearly. AND has higher priority than OR, so parentheses protect you from a mistake:1SELECT * FROM ksiazki
2WHERE (kategoria_id = 1 OR kategoria_id = 2) AND cena > 30;Here we first check the category (one of two), and only then the price. Parentheses work as in mathematics - what is inside is calculated first. Remember them, @name!