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.

Comparison Operators in SQL

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

About admin 133 Articles
Oracle Consultant with Vast Experience in Oracle BI and SQL PLSQL Development

Be the first to comment

Leave a Reply

Your email address will not be published.


*