2.10 SQL Operator
2.10 SQL Operator
By
Mr. Parag R. Sali
Lecturer
Department of Computer Technology
SNJB’s Shri. Hiralal Hastimal ( Jain Brothers)
Polytechnic, Chandwad
Program Name: Computer Engineering Group
Program Code : CO/CM/CW
Semester : Third
Course Title : Database Management System
Course Code : 22319
SQL Operators
SQL OPERATORS
Arithmetic Operators
Comparison Operators
Logical Operators
Set Operators
Checks if the values of two operands are equal or not, if values are not equal then
<> condition becomes true. (a <> b) is true.
Checks if the value of left operand is greater than the value of right operand, if
> yes then condition becomes true. (a > b) is not true.
Checks if the value of left operand is less than the value of right operand, if yes
< then condition becomes true. (a < b) is true.
Checks if the value of left operand is greater than or equal to the value of right
>= operand, if yes then condition becomes true. (a >= b) is not true.
Checks if the value of left operand is less than or equal to the value of right
<= operand, if yes then condition becomes true. (a <= b) is true.
Checks if the value of left operand is not less than the value of right operand, if
!< yes then condition becomes true. (a !< b) is false.
Checks if the value of left operand is not greater than the value of right operand,
!> if yes then condition becomes true. (a !> b) is true.
Roll_no Name City Marks
1 Jay Delhi 87
2 Sai Pune 60
3 Deep Nasik 75
4 Riya Gujrat 93
5 Diya Jalgaon 88
Sr.No. Description
Dept_no Dept_name
101 Comp
102 Mech
103 Civil
104 E&TC
UNION OPERATOR
UNION is used to combine the results of two or
more SELECT statements. However it will eliminate duplicate
rows from its result set.
Syntax :
Select column_name from table1 UNION Select column_name from table2;
Example :
Select Dept_no from Emp UNION Select Dept_no from Dept;
Output :
Dept_no
101
102
103
104
UNION ALL OPERATOR
This operation is similar to Union. But it also shows the
duplicate rows.
Syntax :
Select column_name from table1 UNION ALL Select column_name from table2;
Example : Dept_no
Select Dept_no from Emp UNION ALL Select Dept_no from Dept; 101
102
103
102
101
101
102
103
104
INTERSECT OPERATOR
The Minus operation combines results of two SELECT statements and return only those in the final result, which
belongs to the first set of the result.
Syntax :
Dept_no
104
RANGE SEARCHING OPERATORS – BETWEEN
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a_%' Finds any values that start with "a" and are at least 2
characters in length
WHERE CustomerName LIKE 'a__%' Finds any values that start with "a" and are at least 3
characters in length
WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends with "o"
Example :
SELECT * FROM Emp
WHERE Emp_nameLIKE ‘s%';
Output :