SQL NOT Keyword
The NOT operator is used in a WHERE clause to filter records that do not meet a specified condition. It is commonly used to reverse the result of a logical expression.
SQL NOT Syntax
SQL
x
1
SELECT column1, column2, ...
2
FROM table_name
3
WHERE NOT condition;
SQL NOT with Equality Example
This query selects all patients whose gender is not female.
SQL
1
1
SELECT *
2
FROM Patients
3
WHERE NOT gender = 'F';

SQL NOT with IN Example
This query selects all doctors whose specialty is not Cardiology or Pediatrics.
SQL
1
1
SELECT *
2
FROM Doctors
3
WHERE specialty NOT IN ('Cardiology', 'Pediatrics');

SQL NOT with LIKE Example
This query selects all students whose names do not start with ‘A’.
SQL
1
1
SELECT *
2
FROM Students
3
WHERE name NOT LIKE 'A%';
