Page 31 - Modular_V2.0_SQL_Flipbook
P. 31
Relational Operators
Consider the value of a=10 and b=5 to understand examples in the following table:
Operator Description Example
Checks if value of ‘a’ is equal to value of ‘b’. If yes,
= (a = b) is false
condition becomes true, else false.
Checks is value of ‘a’ is not equal to value of ‘b’. If
!= (a != b) is true
yes, condition becomes true, else false.
Checks if value of ‘a’ is not equal to value of 'b'. If
<> (a <> b) is true
yes, condition becomes true, else false.
Checks if value of ‘a’ is less than value of ‘b’. If yes,
< (a < b) is false
condition becomes true, else false.
Checks if value of ‘a’ is greater than value of ‘b’. If
> (a > b) is true
yes, condition becomes true, else false.
Checks if value of ‘a’ is less than or equal to the value
<= (a <= b) is false
of ‘b’. If yes, condition becomes true, else false.
Checks if value of ‘a’ is greater than or equal to the
>= (a >= b) is true
value of ‘b’. If yes, condition becomes true, else false.
Boolean Operators
SQL provides the following Boolean operators:
Operator Description Example
It returns true if both Boolean expressions SELECT * FROM employee WHERE
AND
are true. department = ‘IT’ AND age = 28;
It returns true if either of the Boolean SELECT * FROM employee WHERE
OR
expressions is true. age = 25 OR age = 26;
It reverses the value of any other Boolean
SELECT * FROM employee WHERE
NOT operator, it means it returns a false if the
department = ‘IT’ AND NOT age = 28;
expression gives a true and vice versa.
Special Operators
The different special operators in SQL are as follows:
Operator Description
ALL This operator returns TRUE if all of the subquery values meet the condition.
ANY This operator returns TRUE if any of the subquery values meet the condition.
This operator is used to indicate a range which otherwise is done using relational
BETWEEN
operator.
EXISTS This operator returns TRUE if the subquery returns one or more records.
29
Handling Records in MySQL

