T-SQL Tutorial T-SQL Advanced Database Management T-SQL References

T-SQL - NOT Keyword



The T-SQL (Transact-SQL) NOT keyword is used with a T-SQL WHERE clause and displays a record where the specified condition is not true.

Syntax

The syntax for using NOT keyword in T-SQL (Transact-SQL) is given below:

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

Example:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To select all records of the Employee table where City is NOT "New Delhi", the query is given below.

    SELECT * FROM Employee
    WHERE NOT City = 'New Delhi';
    

    This result of the query is shown below:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    6HuangBeijing282800

❮ T-SQL Keywords