SQL Not

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

SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;



SQL Not Example

This query selects the first_name, last_name, and gender columns from the patients table.

SELECT first_name, last_name, gender
FROM Patients
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.

SELECT first_name, last_name, contact_number, dob
FROM Patients
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’.

SELECT first_name, last_name, dob
FROM Patients
WHERE NOT first_name LIKE 'A%' AND NOT dob = '1990-01-01';




SQL Not Visual Diagram




SQL Not Labs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top