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 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 SQL Comparison Operators, We are going to use the below-shown data

Customer Table for Comparison

SQL Comparison Operators Examples

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

SQL 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 SQL 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 Equal to = 1

SQL Greater Than >

The SQL 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
Greater Than 2

Less Than <

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

Greater Than or Equal to >=

The SQL Greater than or Equal 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

Less Than or Equal to <=

The SQL Less than or Equal to 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
SQL Comparison Operators 5

Not Equal to <>

SQL Not Equal to 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 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 !=

The SQL Not Equal to operator is same as <>. For example, The following 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

Not Less Than !<

The Not Less than opertor 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 !<

Not Greater Than 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

Comparison Operators in SQL 9

Comments are closed.