SQL Server Comparison Operators

SQL Server Comparison Operators

Comparison operators can be used to specify the condition in the SQL query.

Comparison operators are used to retrieve the rows from a database table based on condition specified in the WHERE clause.

SQL Server supports the following comparison operators to specify condition in SQL.

Operator Description
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<>, != Not equal to
!> Not greater than
!< Not less than

Employee Table

Let us consider the example 'Employee' database table.

Employee table output

Equal to (=) operator

Checks whether left and right side values are equal or not.

SELECT Name, City, Email, Salary
FROM Employee
WHERE DeptId = 1
Output:
comparison equal to operator output

Less than (<) operator

Checks whether left side is less than right side value.

SELECT Name, City, Email, Salary
FROM Employee
WHERE DeptId < 2
Output:
comparison less than operator output

Greater than (<) operator

Checks whether left side is greater than right side value.

SELECT Name, City, Email, Salary
FROM Employee
WHERE DeptId > 1
Output:
comparison greater than operator output

Less than or equal to (<=) operator

Checks whether left side is less than or equal to right side value.

SELECT Name, City, Email, Salary
FROM Employee
WHERE DeptId <= 2
Output:
comparison less than or equal to operator output

Greater than or equal to (>=) operator

Checks whether left side is greater than or equal to right side value.

SELECT Name, City, Email, Salary
FROM Employee
WHERE DeptId >= 1
Output:
comparison greater than or equal to operator output

Not equal to (<>, !=) operator

Checks whether left side is less than right side value.

SELECT Name, City, Email, Salary
FROM Employee
WHERE DeptId != 2
SELECT Name, City, Email, Salary
FROM Employee
WHERE DeptId <> 2
Output:
comparison less than operator output



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^