= keeps the rows that are equal to a value. Other operators keep a range of values.
| Operator | Means | Example | Keeps |
|---|---|---|---|
< | less than | price < 20 | 14.00, not 20.00 |
> | greater than | stock > 50 | 55, not 50 |
<= | less than or equal to | price <= 20 | 14.00 and 20.00 |
>= | greater than or equal to | stock >= 50 | 50 and 55 |
<> | not equal to | status <> 'pending' | every other status |
!= | not equal to | status != 'pending' | the same as <> |
<> is the form in the SQL standard. != works in PostgreSQL and MySQL too.
products
| id | name | price |
|---|---|---|
| 5 | Root Hoodie | 49.95 |
| 6 | Cluster Socks | 9.50 |
| 7 | Linux Sticker Pack | 6.00 |
| 9 | Holo Kraken Sticker | 3.50 |
| 10 | Kernel Panic Mug | 14.00 |
Numbers, text and dates
The operators work on each type in its own order:
| Type | Order | Example |
|---|---|---|
| number | smaller to larger | price < 20 |
| text | alphabetical, one character at a time | name < 'M' keeps names that start with A to L |
| date | earlier to later | order_date >= '2025-03-01' |
Write a date as text in the form 'YYYY-MM-DD', in single quotes. PostgreSQL compares it with the date column as a date.
In this database, every upper-case letter comes before every lower-case letter: 'Z' < 'a' is true.