Skip
Arish's avatar

9. Filter with Not Equal


Not Equal Operator

To find records that DON'T match a value, use != or <>.

Syntax

sql
1-- Using !=
2SELECT * FROM students WHERE course != 'Python';
3
4-- Using <> (ANSI standard)
5SELECT * FROM students WHERE course <> 'Python';

Both operators work the same way.

Example: Non-Python Students

sql
1SELECT * FROM students
2WHERE course != 'Python';

Result

idnameagecoursemarks
2Bob12JavaScript78
4David13Ruby65
6Frank14HTML71

More Examples

sql
1-- Students not in grade A
2SELECT * FROM students WHERE grade != 'A';
3
4-- Students not aged 12
5SELECT * FROM students WHERE age != 12;
6
7-- Students with marks not equal to 85
8SELECT * FROM students WHERE marks <> 85;

!= vs <>

OperatorDescription
!=Common, widely supported
<>ANSI SQL standard

Both are correct. Choose one and be consistent.

Important Note

Not equal does NOT match NULL values:

sql
1-- This won't return rows where course IS NULL
2SELECT * FROM students WHERE course != 'Python';

To include NULLs, use IS NULL separately (covered later).