SQL Server Operators

There are about 5 SQL Server Operators categories.

1) Arithmetic operators are:

+(addition)
-(subtraction)
*(multiplication)
/(division)
%(modular)

2)Relational Operators:

>,<,>=,<=,=,<> (or) !=

3)Logical Operators:

AND, OR, NOT

4)Special operators:

BETWEEN, IN, LIKE, IS, ANY, ALL, EXISTS

5)Set Operators:

UNION, UNION ALL,INTERSECT, EXCEPT

To know moire about set operators go through following link

BETWEEN Operator: BETWEEN operator is used to get range of values. As well as not in the given range. Between operator always work with lower and upper limits. But not upper and lower limits.

Example:

Display employee names who are getting getting salary between 4000 and 6000.

select * from emp
where salary between 4000 and 6000

Display employee records who are working as clerk or manager

select * from emp
where job=’clerk’ or job=’manager’

In Operator: In operator is used to compare column value with multiple values

Display employee records who are working as clerk or manager

select * from emp
where jon in(‘clerk’,’manager’)

Display employee records who are not working for department 10 or 20

select * from emp
where deptno not in(10,20)

Display employee records earning between 4000 and 6000 and earning multiples of 50 and working as clerk or manager but not in department 10 or 20.

select *from emp
where salary between 4000 and 6000
and salary%50=0
and
jon in(‘clerk’,’manager’)
and deptno not in(10,20)

LIKE Operator:

Powered by k2schools