NOT Operator - SQL


Overview


The NOT Operator in SQL is used to negate a condition in a WHERE clause. It returns true if the specified condition is false.

Syntax:

SELECT column
FROM table_name
WHERE NOT condition

NOT condition negates the specified condition, returning true if the condition is false.

Sample Data:

first_name salary
Frank 123000
Jane 135000
Ashley 140000
Glenn 115000
Kelly 125000
Richard 120000
George 105000
Kyle 200000
James 107000
Gustavo 100000

Example


In this example, we are returning the first_name and the salary column. We then use the NOT operator to negate the salary is greater than 125000 condition and turn it into salary is not greater than 125000.

Example:

SELECT first_name, salary
FROM company.employees
WHERE NOT salary > 125000