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 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.
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
In my previous article I have given details about application support engineer day to day…
In my previous articles I have given the roles and responsibilities of L1,L2 and L3…
In my previous articles i have given the hierarchy of production support in real company…
In this article i would like to provide information about production support organization structure or…
In my previous article I have given roles for L1 and L2 support engineer with…
I have started this new series of how to become application support engineer. This article…