Comparing Values
Equal, not equal, more, less.
So far we've used equals, less than, and greater than or equal. SQL has six of these comparison signs in total. Once you know them, you can ask almost any simple question.

- Six comparison signs
- You know three already
- Learn them once, use forever
The six comparisons
Here they are. Equals checks if two things are the same. The two signs together, less than and greater than, mean not equal. Then less than, greater than, and the two with an equals sign, which include the value itself. So price less than or equal to ten includes a book that costs exactly ten.
| Sign | Means | Example |
|---|---|---|
| = | equal to | genre = 'Romance' |
| <> | not equal to | status <> 'delivered' |
| < | less than | price < 10 |
| > | greater than | stock > 50 |
| <= | less than or equal | price <= 10 |
| >= | greater than or equal | published >= 2024 |
The newest books
Let's find the newest books. Published greater than or equal to twenty twenty four. Run it. Six recent books. Helen could feature these in a new arrivals section.
SELECT title, published
FROM books
WHERE published >= 2024;โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ โ title โ published โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโค โ Stars Over Lagos โ 2024 โ โ Numbers Don't Lie โ 2025 โ โ The Map Maker's Daughter โ 2025 โ โ Deep Water โ 2025 โ โ One Pan Dinners โ 2025 โ โ The Painted Door โ 2025 โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
Not equal
Now, how many orders were not delivered? We use not equal, and a new trick. Count star counts the rows, instead of showing them. We'll learn counting properly later. Run it. Three hundred and thirty three orders were cancelled, returned, or are still on the way.
SELECT COUNT(*)
FROM orders
WHERE status <> 'delivered';โโโโโโโโโโโโ โ COUNT(*) โ โโโโโโโโโโโโค โ 333 โ โโโโโโโโโโโโ
Books by one author
Your turn. Find the title and author of every book written by Mira Hale. Pause and try it. Here's a solution. Where author equals Mira Hale, in single quotes. Three books.
Show the title and author of every book by Mira Hale
Show hint
Text goes in single quotes
Show solution
SELECT title, author
FROM books
WHERE author = 'Mira Hale';โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ โ title โ author โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโค โ The Silent Orchard โ Mira Hale โ โ The Last Lighthouse โ Mira Hale โ โ Murder at Mill Lane โ Mira Hale โ โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
Summary
You can now filter with any of the six comparisons, on numbers or text. Next, combining tests, so you can ask questions like, cheap fantasy books.
Key takeaways- = <> < > <= >=
- <> means not equal
- COUNT(*) counts rows