Two operators mean “not equal”: != and <> (the SQL-standard spelling). WHERE department <> 'Sales' keeps every row except Sales. One trap mirrors NULL logic: comparing against NULL with != returns UNKNOWN, so those rows silently vanish — combine with IS NOT NULL when the column can be blank.
--how it works
1
Two spellings, one meaning
!= and <> both mean "not equal"; <> is the ANSI standard, != the popular alias.
2
Exclude exactly one value
WHERE department <> 'Sales' removes only exact Sales rows.
3
Chain exclusions with AND
dept <> 'Sales' AND dept <> 'Marketing' — or the tidier NOT IN ('Sales', 'Marketing').
4
Prefer NOT IN for lists
One clause, obvious intent, identical plan.
5
Mind the NULL hole
salary <> 50000 also drops rows where salary is NULL — the comparison is UNKNOWN there.
--visualization
department <>
Stage 1 / 8
WHERE department <> 'Sales' — everything EXCEPT that exact value survives.
--example
query.sql
1SELECTname,department
2FROMemployees
3WHEREdepartment<>'Sales';
Result
name
department
Alice
Engineering
Cynthia
Engineering
David
Marketing
Farid
Engineering
Bob and Elena (Sales) are excluded; everyone else survives. Try <> 'Engineering' in the visualization to flip which half disappears.
--variants
Exclude one department
Everything except Sales.
query.sql
1SELECTname,department
2FROMemployees
3WHEREdepartment<>'Sales';
Result
name
department
Alice
Engineering
Cynthia
Engineering
David
Marketing
Farid
Engineering
1Bob and Elena are the two Sales rows — out.
2The other four pass the inequality.
3<> and != behave identically here.
Exclude several values
AND-chained inequalities vs NOT IN.
query.sql
1SELECTname,department
2FROMemployees
3WHEREdepartment<>'Sales'
4ANDdepartment<>'Engineering';
Result
name
department
David
Marketing
1Both tests must pass — only Marketing survives.
2Equivalent: department NOT IN ('Sales', 'Engineering').
3NOT IN scales to ten values; AND-chains do not.
Numbers and <>
Same operator, numeric column.
query.sql
1SELECTname,salaryFROMemployees
2WHEREsalary<>52000;
Result
name
salary
Alice
85000
Cynthia
91000
David
47000
Elena
58000
Farid
73000
1Only Bob earns exactly 52000 — he is excluded.
2The other five pass; no rounding surprises with integers.
3On DECIMAL money columns, <> against a literal is exact by design.
The NULL hole
Where <> silently loses rows.
query.sql
1SELECTnameFROMemployees
2WHEREbonus<>0;
Result
name
bonus
David
3000
Elena
2500
Alice
5000
1Bob, Cynthia and Farid have bonus NULL — 3000-row comparisons cannot call them <> 0.
2Their rows vanish without error or warning.
3Fix: bonus <> 0 OR bonus IS NULL — or COALESCE(bonus, 0) <> 0.
--key facts
Standard form<> works in every SQL dialect; != is near-universal sugar
NULL trapanything <> NULL is UNKNOWN — add IS NOT NULL when unsure
ReadabilityNOT IN lists beat long chains of <> AND <>
--use cases
Excluding sentinel rows: status <> 'archived'
Blacklists: category NOT IN ('internal', 'test')
Removing the current user/row from a comparison list
Interview trap questions about NULL and inequality
--under the hood
<> is generally NOT index-friendly on its own — "not equals" matches most rows, so engines prefer full scans plus filter.
When one value dominates a table, exclude it explicitly and let the rest ride an index on a positive predicate.
Practice SQL interview questions
Every SQL lesson maps to the matching interview topic, with answers written for current SQL engines.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses →Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free →Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books →