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

The Essential Guide to Cryptocurrency Exchange Platform Development for Beginners and Beyond

Introduction Cryptocurrencies took the world by storm, setting up a new financial system and breaking…

5 months ago

Top 20 System Administrator Interview Questions and answers

In my previous article I have given Top 20 technical support interview questions with its…

8 months ago

Desktop Support Scenario Based Interview Questions

In my previous articles I have given 15 most asked desktop support interview questions with…

8 months ago

How Do Business Analysts Use SQL for Their Needs?

A business analyst is someone who is versed in processes of data analysis used for…

8 months ago

Top 15 Control-M Interview Questions with Answers

In my previous article I have already given top questions and answers for Desktop support…

8 months ago

Top 20 SQL Interview Questions for Production Support

In my previous article I have given unix production support interview questions and answers. In…

8 months ago