At the heart of every condition is a comparison of two values. The scribe asks: "Is the price greater than 30? Does the year of publication equal 1990?". In MySQL we answer such questions with comparison operators.
| Operator | Meaning | Example | |----------|---------|---------| |
= | equal | cena = 30 |
| <> | not equal | kraj <> 'Polska' |
| < | less than | rok_wydania < 1900 |
| > | greater than | cena > 50 |
| <= | less than or equal | cena <= 20 |
| >= | greater than or equal | rok_wydania >= 2000 |Note, @name: in MySQL we check equality with a single
= sign (not == as in JavaScript). Inequality is written as <>.1SELECT * FROM ksiazki
2WHERE cena > 50;This means: "Show all books whose price exceeds 50 coins".
The operators
<= and >= also include the boundary value. The condition cena <= 20 returns both books cheaper than 20 coins and those costing exactly 20:1SELECT * FROM ksiazki
2WHERE cena <= 20;And the condition
rok_wydania >= 2000 also includes the year 2000 itself:1SELECT * FROM ksiazki
2WHERE rok_wydania >= 2000;Remember a simple rule: a
< or > sign without a line does not include the boundary, but with a line <= / >= it does include it. A small difference, but it can change the whole result!