Categories: SQL Tutorials

What are Comparison Operators in SQL | Comparison Operators in SQL Examples

Comparison Operators in SQL:

In my previous articles i have given the idea of Arithmetic operators in SQL as well as logical operators in SQL. The third type of operators are Comparison Operators in SQL which are used to compare two or more expressions.The Comparison Operators in SQL are most used operators in the programming or adding the business logic to specific program.This article will give you the idea about Comparison Operators in SQL with real industry examples.

Comparison Operators in SQL Examples :

Comparison Operators are used to compare different variables or different values from the database table.

1.Equal To (=):

Checks the values between 2 variables or operands are equal to or not.If the values are equal to then it will return true else false.

Example:

Select * from Employee where EMPNO=10;

The statement will fetch the record of employee whose EMPNO is 10.

2.Not Equal to(!=,<>):

Checks the values between 2 variables or operands are equal to or not.If the values are not equal to then it will return true else false.

Example:

Select * from Employee where EMPNO!=10;

The statement will fetch all records of employee whose EMPNO is not 10.

3.Greater than (>):

Checks the values between 2 variables or operands if Left side operand or variable value is Greater than Right side operand or variable then it will fetch true or false.

Example:

Select * from Employee where Salary >10000;

The statement will fetch all records of employee whose Salary is greater than 10000.

4.Less than (<):

Checks the values between 2 variables or operands if Left side operand or variable value is less than Right side operand or variable then it will fetch true or false.

Example:

Select * from Employee where Salary <10000;

The statement will fetch all records of employee whose Salary is less than 10000.

5.Greater than and Equal to (>=):

Checks the values between 2 variables or operands if Left side operand or variable value is Greater than  and Right side operand or variable then it will fetch true or false.

Example:

Select * from Employee where Salary =>10000;

The statement will fetch all records of employee whose Salary is greater than and equal to 10000.Using this operator the employees whose salary is equal to 10000 are also fetched.

6.Less than (<=):

Checks the values between 2 variables or operands if Left side operand or variable value is less than and equal to Right side operand or variable then it will fetch true or false.

Example:

Select * from Employee where Salary <=10000;

The statement will fetch all records of employee whose Salary is less than and 10000.Using this operator the employees whose salary is equal to 10000 are also fetched.

4.Negation Operators in SQL:

Negation Operators are operators which has negation condition like ‘Not’ Condition.

NOT Operator:

Not operator is negation operator which reverses the meaning of logical operator.The Not operator is used before Logical operator like Not In,Not Exist etc.

Example:

Select * from Student where name not in (‘Divya’);

The above statement will fetch all the records from Student table where name is not Divya.

Hope this article has given you idea about the comparison operators in sql with real examples.If you like this article or if you have any suggestions for this article dont forget to comment in comment section.

h

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Recent Posts

Application Support Engineer Day to day responsibilities

In my previous articles I have given the roles and responsibilities of L1,L2 and L3…

1 day ago

What is mean by SLA ( Service Level Agreement) with Examples?

In my previous articles i have given the hierarchy of production support in real company…

4 days ago

What is Production support Hierarchy in organization?

In this article i would like to provide information about production support organization structure or…

4 days ago

What are roles and responsibilities for L3 Support Engineer?

In my previous article I have given roles for L1 and L2 support engineer with…

4 days ago

What are roles and responsibilities of L2 Engineer?

I have started this new series of how to become application support engineer. This article…

4 days ago

What are Roles and Responsibilities of L1 Support Engineer with real industry examples?

In this series we are starting with Roles and responsibilities of L1 support engineer .…

4 days ago