You are on page 1of 12

SQL

Operators
1. Arithmetic Operator:
+, -, *, /, %
2. Relational Operator:
<
>
>=
<=,
<> or !=
= (both assignment and comparison)
3.Logical Operator: (Used to combine two operations)
 AND
 OR
 NOT

4 .Special Operator:
 BETWEEN
 IN
 LIKE
 IS
Emp_No Ename Sal Comm Dept_No Hiredate

1 Smith 15000 5000 10 2011-03-15

2 Allen 20000 20 2011-05-20


3 Harry 18000 10 2011-11-20

4 Williams 30000 30 2011-01-11

5 Sandra 17000 7000 20 2011-07-21


Display name of every employee along with its total
income –

Select ename ,sal+comm as income from employee;

Display emp records whose sal is multiple of 3;

Select * from employee where sal%3=0;


Display records of employee whose salary is from 15000
to 20000

select * from employee where sal>=15000 And


sal<=20000;

Display records of those employee who don’t earn


between 15000 to 20000

select * from employee where sal<15000 or


sal>20000;
USE of BETWEEN Operator
Between operator is used to compare column value with
range of values

Select * from employee where sal between 15000


and 20000;

Select * from employee where sal not between 15000


and 20000;
Use of IN Operator
Used to compare column value with multiple values.

Syntax:
IN(v1,v2,……,vn)
NOT IN(v1,v2……vn)

SELECT * FROM employee WHERE sal IN(15000,18000);

Select * from employee WHERE sal NOT


IN(15000,18000);
Use of LIKE Operator
Use to compare column values with patterns.

Syntax:

LIKE ‘Pattern’

NOT LIKE ‘Pattern’


Pattern consist of various symbols like –

% - To replace none or many characters

_(underscrore) – To replace exactly one char


Display employee records whose name start with S.

Select * from employee where ename like ‘S%’;

Display employee records whose name ends with S.

Select * from employee where ename like ‘%S’;

Display employee records where A is the second char in


there name
Select * from employee where ename like ‘_A%’;
Select name, address from student where tot_marks=68
AND branch=‘BE’;

You might also like