SQL Comparison Operators

The SQL Server Comparison Operators will be very useful for comparing the Column values with the valid Expression. The following table shows the list of available comparison operators in SQL Server, and equal to is the most commonly used one.

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 demo, we will use the below-shown data.

Customer Table

SQL Comparison Operators Examples

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

Equal to =

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

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

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

SQL Server Greater Than > Comparison Operator

The Greater than Operator will display the records whose column value is Greater than the given expression. For example, The following Server Greater than 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 Greater Than 2

SQL Server Less Than Comparison Operator <

The Less than Operator will display the records whose column value is Less than the given expression. The following Less than comparison Operators 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 Less Than 3

Greater Than or Equal to >=

It is used to 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 comparison operators in sql 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 comparison operator <=

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

For example, the 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
Less Than or Equal to 5

Not Equal to <>

It will display the records whose column value is not equal to the given expression.

For example, The following 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 except [Yearly Income] to be Equal to 60000

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

SQL Not Equal To Comparison Operator !=

The Not Equal to operator is the same as <>. For example, The following Not Equal to operator query will find 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
Not Equal to Comparison Operators in SQL Server 7

Not Less Than !<

The 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

SELECT [FirstName]
      ,[LastName]
      ,[YearlyIncome]
      ,[Education]
      ,[Occupation]
 FROM [Customer]
 WHERE [YearlyIncome] !< 70000
SQL Not Less Than !<

SQL Not Greater Than Comparison Operator !>

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

This 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
Not Greater Than 9
Categories SQL

Comments are closed.