SQL Comparison Operators
SQL comparison operators such as >= compare numbers in a WHERE condition. >= means greater than or equal to. A number is written without quotes.
The examples below use this books table. Change a query and press Run to see its result.
Table: books
| title | author | pages |
|---|---|---|
| Wonder | R. J. Palacio | 320 |
| Matilda | Roald Dahl | 240 |
| Holes | Louis Sachar | 272 |
| The BFG | Roald Dahl | 208 |
Keep numbers at or above a value with >=
WHERE pages >= 240 keeps the books with 240 pages or more:
SELECT title, pagesFROM booksWHERE pages >= 240;Wonder, Matilda and Holes are in the result. Matilda has exactly 240 pages, and >= keeps it. The number 240 has no quotes, because pages holds numbers, not text.
Check that >= keeps the number itself
Compare it with >, which means greater than. > keeps only the values bigger than the number:
SELECT title, pagesFROM booksWHERE pages > 240;Now only Wonder and Holes are in the result. Matilda is left out, because 240 is not greater than 240. For "at least 240", use >=.
Note: Write >= with the = second and no space between the two signs.
See also: SQL WHERE.
Your turn
Add a WHERE line so the query shows only the books with 272 pages or more.
title | pages -------+------ Wonder | 320 Holes | 272 (2 rows)
-- add a WHERE line after FROM, and move the ; to the endSELECT title, pagesFROM books;