SQL Comparison Operators

The SQL Comparison Operators will be very useful to compare the Column values with the valid Expression. The following table shows the list of available comparison operators in SQL Server.

SQL Comparison OperatorsDescription
=Equal to
>Greater than
<Less than
>=Greater than or Equal to
<=Less than or Equal to
<>NOT Equal to
!=Not Equal to
!>Not Greater than
!<Not Less than

For this SQL Server Comparison Operators, We are going to use the below-shown data

SQL Comparison Operators

SQL Comparison Operators Examples

The following are the list of SQL Comparison operators with an example of each.

SQL Equal to Operator (= Operator)

The SQL Equals Operator is the most used comparison operator. It will display the records whose column value is exactly equal to the given expression.

For example, the following SQL comparison operator query will find all the Customers present in the Customers table whose Occupation is exactly equal to Management

— SQL Server Comparison Operators Example

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [Occupation] = 'Management'
SQL Comparison Operators 1

SQL Greater Than Operator (> Comparison Operator)

The SQL Greater than Operator will display the records whose column value is Greater than the given expression. For example, The following SQL Server Greater than Operator query will find all the Customers present in the Customers table whose [Yearly Income] is Greater than 60000

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] > 60000
SQL Comparison Operators 2

SQL Less Than Operator (< Operator)

The SQL Less than Operator will display the records whose column value is Less than the given expression. The following SQL Less than Operator query will find all the Customers present in the Customers table whose [Yearly Income] is Less than 70000

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] < 70000
SQL Comparison Operators 3

SQL Greater Than or Equal to Operator (>= Operator)

The SQL Greater than or Equal to Operator will display the records whose column value is greater than or equal to the given expression. For example, The following Greater than or Equal to Operator query will find all the Customers present in the Customers table whose [Yearly Income] is Greater than or equal to 60000

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] >= 60000
SQL Comparison Operators 4

SQL Less Than or Equal to Operator (<= Operator)

The SQL Less than or Equal to Operator will display the records whose column value is Less than or equal to the given expression.

For example, The SQL Less than or Equal to Operator following query will find all the Customers available in the Customers table whose [Yearly Income] is Less than or equal to 70000

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] <= 70000
SQL Comparison Operators 5

SQL Not Equal to Operator (<> Operator)

SQL Not Equal to Operator will display the records whose column value is Not equal to the given expression.

For example, The following SQL Not Equal to operator query will find all the Customers available in the Customers table whose [Yearly Income] is Not Equal to 60000. It means, it will display all the records expect [Yearly Income] is Equal to 60000

-- SQL Server Comparison Operators Example
SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] <> 60000
Comparison Operators in SQL 6

SQL Not Equal To Operator (!= Operator)

The SQL Not Equal to operator is same as <> Operator. For example, The following SQL Not Equal to operator query will finds the Customers present in the Customers table whose [Yearly Income] is Not Equal to 60000.

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] != 60000
Comparison Operators in SQL 7

SQL SQL Not Less Than Operator (!< Operator)

SQL Not Less than Operator will display the records whose column value is Greater than or Equal to the given expression.

The SQL Not Less than operator query finds the Customers available in the Customers table whose [Yearly Income] is Not Less than 70000. It means, it will display all the records whose [Yearly Income] is greater than or equal to 70000

-- SQL Server Comparison Operators Example
SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] !< 70000
Comparison Operators in SQL 8

SQL Not Greater Than Operator (!> Operator)

The Not Greater than Operator will display the records whose column value is Less than or Equal to the given expression.

This SQL Not Greater than Operator query will find the Customers whose [Yearly Income] is Not Greater than 70000. It means, it will display all the records whose [Yearly Income] is less than or equal to 70000

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] !> 70000

Comparison Operators in SQL 9

Comments are closed.