SQL Server Tutorial
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 |
Let us consider the example 'Employee' database table.
Checks whether left and right side values are equal or not.
SELECT Name, City, Email, Salary FROM Employee WHERE DeptId = 1Output:
Checks whether left side is less than right side value.
SELECT Name, City, Email, Salary FROM Employee WHERE DeptId < 2Output:
Checks whether left side is greater than right side value.
SELECT Name, City, Email, Salary FROM Employee WHERE DeptId > 1Output:
Checks whether left side is less than or equal to right side value.
SELECT Name, City, Email, Salary FROM Employee WHERE DeptId <= 2Output:
Checks whether left side is greater than or equal to right side value.
SELECT Name, City, Email, Salary FROM Employee WHERE DeptId >= 1Output:
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 <> 2Output:
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page