Equal (=) & Not Equal (<>, !=)
Use = to keep exact matches and <> / != to keep everything except a value.
The most common filters ask "is it exactly this?" or "is it anything but this?". Show me MI players uses equal. Show me everyone except MI uses not equal.
Definition
A comparison operator compares two expressions and returns TRUE, FALSE, or UNKNOWN (when either side is NULL).
=(equal) is TRUE when both values are exactly the same.<>/!=(not equal) is TRUE when the two values are different.
<> is the ISO/ANSI standard spelling. != means exactly the same thing; SQL Server, MySQL and PostgreSQL all accept it, but it is not part of the SQL standard. Prefer <> in professional code — though both are fine.
Syntax
sql
SELECT column_list
FROM table_name
WHERE column_name = value; -- exact match
SELECT column_list
FROM table_name
WHERE column_name <> value; -- everything except value (same as !=)| Operator | Read as | TRUE when | Example |
|---|---|---|---|
= | equal to | both sides are the same | team = 'MI' |
<> | not equal to | sides are different | team <> 'MI' |
!= | not equal to | same as <> | team != 'MI' |
Example — = keeps exact matches
sql
SELECT *
FROM players
WHERE country = 'India';| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 2 | Rohit Sharma | MI | India | 500 |
| 4 | MS Dhoni | CSK | India | 350 |
| 6 | Jasprit Bumrah | MI | India | 20 |
= keeps rows where the value is exactly the same — so 4 of the 6 players stay.
Example — <> keeps everyone except MI
sql
SELECT *
FROM players
WHERE team <> 'MI';| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 3 | Jos Buttler | RR | England | 850 |
| 4 | MS Dhoni | CSK | India | 350 |
| 5 | David Warner | DC | Australia | 700 |
How it works: FROM loads 6 rows → WHERE drops the two MI rows (Rohit Sharma and Jasprit Bumrah) → SELECT shows all columns. Writing WHERE team != 'MI' gives the identical result.
Not equal and NULL — a hidden trap
In player_profiles, David Warner's team is NULL (unknown). Look what happens:
sql
SELECT name, team
FROM player_profiles
WHERE team <> 'MI';| name | team |
|---|---|
| Virat Kohli | RCB |
| Jos Buttler | RR |
| MS Dhoni | CSK |
David Warner is missing, even though NULL is "not MI". Comparing NULL with anything (NULL <> 'MI') gives UNKNOWN, and WHERE throws away UNKNOWN rows. If you want him too, add OR team IS NULL.
Case sensitivity
Whether team = 'mi' matches 'MI' depends on the collation (the text-comparison rules) of the database:
| Database | 'MI' = 'mi' |
|---|---|
SQL Server (default ..._CI_AS collation) | TRUE — case-insensitive |
| MySQL (default collation) | TRUE — case-insensitive |
| PostgreSQL | FALSE — case-sensitive |
| This playground (SQLite) | FALSE — case-sensitive |
Tip: To be safe everywhere, write values in the same case as the data, or compare
UPPER(team) = 'MI'.
Common mistakes
- ❌
WHERE team = MI→ missing quotes. ✅WHERE team = 'MI' - ❌
WHERE team = NULL→ never TRUE. ✅WHERE team IS NULL - ❌
WHERE team =! 'MI'→ not an operator. ✅<>or!= - ❌ Hidden spaces:
' India'(leading space) does not equal'India'. SQL Server ignores trailing spaces in=comparisons, but never leading ones — keep values clean.
Interview tip
Q: Is there any difference between <> and !=?
A: No difference in result or performance. <> is the ANSI standard; != is a widely supported extension. Neither will match NULL — use IS NULL / IS NOT NULL for that.
Key points to remember
- = keeps rows where the value is exactly equal to the given value.
- <> and != both mean 'not equal' and keep everything except the matching value.
- <> is the ISO/ANSI standard; != is a common extension — results are identical.
- Any comparison with NULL (=, <>) returns UNKNOWN, so NULL rows are silently dropped.
- Text values need single quotes; double quotes mean an identifier in SQL Server.
- SQL Server's default collation is case-insensitive, so 'MI' = 'mi' is TRUE there.
Try it yourself
= : only Indian players
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
<> and != : everyone except MI
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
The NULL trap with <>
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Practice: not from India
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.
