T-SQL - Not equal to (<>) Operator
The T-SQL (Transact-SQL) <> (not equal to) operator checks if the value of left operand is not equal to the value of right operand and returns true if the condition is true, false otherwise.
Syntax
The syntax for using not equal to operator in T-SQL (Transact-SQL) is given below:
expression <> expression
Parameters
expression |
Any valid expression. Both expressions must have implicitly convertible data types. |
Example:
Consider a database table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
To select records of table where Age of the person is not equal to 28, the query is given below.
SELECT * FROM Employee WHERE Age <> 28;
The query will produce following result:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
❮ T-SQL Operators