The SQL Not clause is sused to filter records by excluding those that meet a certain condition. It is essentially the opposite of the WHERE clause condition.
SQL Not Syntax
SQL
x
1
SELECT column1, column2, ...
2
FROM table_name
3
WHERE NOT condition;
SQL Not Example
This query selects the first_name, last_name, and gender columns from the patients table.
SQL
1
1
SELECT first_name, last_name, gender
2
FROM Patients
3
WHERE NOT gender = 'F';

SQL NOT Using NOT with Multiple Conditions Example
This query selects the first_name, last_name, contact_number and dob columns from the Patients table, applying a condition using NOT operator.
SQL
1
1
SELECT first_name, last_name, contact_number, dob
2
FROM Patients
3
WHERE NOT (contact_number IS NOT NULL OR dob > '1985-01-01');

SQL NOT Combining NOT with Other Clauses Example
This query retrieves all the patients whose first_name does not start with the letter “A” and whose dob (date of birth) is not exactly ‘1990-01-01’.
SQL
1
1
SELECT first_name, last_name, dob
2
FROM Patients
3
WHERE NOT first_name LIKE 'A%' AND NOT dob = '1990-01-01';

SQL Not Visual Diagram
