Greater / Less Than (> >= < <=)
Filter numbers, dates and text by size using >, >=, < and <=, and know exactly when the boundary value is included.
"Who scored more than 500 runs?" "Which innings were below 50?" These questions need operators that compare size, not just equality. The big thing to get right is the boundary — is 500 itself included or not?
Definition
The relational comparison operators
>,>=,<and<=compare two values by their order (numeric size, date order, or alphabetical order for text) and return TRUE, FALSE, or UNKNOWN (if either side is NULL).
- Strict operators (
>,<) exclude the boundary value.- Inclusive operators (
>=,<=) include the boundary value.
Syntax
sql
SELECT column_list
FROM table_name
WHERE column_name > value; -- also >=, <, <=| Operator | Meaning | runs ? 500 keeps Rohit (500)? |
|---|---|---|
> | greater than | ❌ No — 500 is not greater than 500 |
>= | greater than or equal to | ✅ Yes |
< | less than | ❌ No |
<= | less than or equal to | ✅ Yes |
Example — > 500 (boundary excluded)
sql
SELECT *
FROM players
WHERE runs > 500;| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 3 | Jos Buttler | RR | England | 850 |
| 5 | David Warner | DC | Australia | 700 |
500 itself is not included — Rohit Sharma (exactly 500) is crossed out.
Example — >= 500 (boundary included)
sql
SELECT *
FROM players
WHERE runs >= 500;| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 2 | Rohit Sharma | MI | India | 500 |
| 3 | Jos Buttler | RR | England | 850 |
| 5 | David Warner | DC | Australia | 700 |
>= also keeps the boundary, so Rohit (500) stays.
Example — < 500 and <= 500
sql
SELECT * FROM players WHERE runs < 500;| id | name | team | country | runs |
|---|---|---|---|---|
| 4 | MS Dhoni | CSK | India | 350 |
| 6 | Jasprit Bumrah | MI | India | 20 |
sql
SELECT * FROM players WHERE runs <= 500;| id | name | team | country | runs |
|---|---|---|---|---|
| 2 | Rohit Sharma | MI | India | 500 |
| 4 | MS Dhoni | CSK | India | 350 |
| 6 | Jasprit Bumrah | MI | India | 20 |
Notice: > 500 (3 rows) + <= 500 (3 rows) = all 6 players. Opposite operators split the table perfectly — unless NULLs exist, which fall into neither group.
Works on dates and text too
- Dates compare by calendar order:
debut < '2010-01-01'= debuted before 2010. - Text compares alphabetically (using the collation):
name > 'M'= names that come after "M" in the dictionary. Careful:'MS Dhoni' > 'M'is TRUE, because a longer string that starts with "M" sorts after plain "M".
Common mistakes
- ❌ Using
>when the question says "at least 500". ✅ "at least" =>=, "more than" =>, "at most" =<=, "less than / below" =<. - ❌
WHERE runs => 500→ wrong order of symbols. ✅>=(the=always comes second). - ❌
WHERE runs > '500'on a number column — works in SQL Server through implicit conversion, but compare numbers with numbers to avoid surprises. - ❌ Forgetting NULLs:
WHERE runs < 50does not return innings where runs is NULL.
SQL Server extra (rarely used)
SQL Server also accepts !< (not less than, same as >=) and !> (not greater than, same as <=). They are not standard SQL — just recognise them if you see them in old code.
Interview tip
Q: Do WHERE runs > 500 and WHERE NOT runs <= 500 always return the same rows?
A: Yes — both drop NULL runs, because NOT UNKNOWN is still UNKNOWN. But WHERE runs > 500 plus WHERE runs <= 500 together do not cover NULL rows.
Key points to remember
- > and < are strict: the boundary value itself is excluded.
- >= and <= are inclusive: the boundary value is kept.
- 'More than' = >, 'at least' = >=, 'less than' = <, 'at most' = <=.
- These operators work on numbers, dates (calendar order) and text (alphabetical order).
- Rows with NULL in the compared column are never returned by > >= < <=.
- The = sign always comes second: >= and <=, never => or =<.
Try it yourself
> vs >= on the boundary (500)
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
< vs <=
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Comparing dates
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Practice: at least 700 runs
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Revision Flashcards
Tap a card to flip it and see the answer.
