Friday, 18 January 2013

Relational operator in SQL

Relational operator(< > = etc)

The relational operators are used in condition to compare none expression with another. They are used in where class in the following format.


Where exp operation value

Select ename, job, depno
From emp
Where job=’clerk’

Select dname, deptno
From dept
Where deptno>20;

Select ename, sal, commission
From emp
Where commission>sal;
Logical operator: (and or not)

And and or are used to give two or more conditions in a where clause not negates the search condition

select empno, ename, job, sal
from employee
where sal between 1000 and 2000 or job=’clerk’;

select empno, empname, job, sal
from employee
where sal between 1000 and 2000 and job=’clerk’;
select empno,  ename, job, sal
from employee
where sal>1500
and job=’manager’

or job=’salesman’;

* select empno, empname, job,sal
from employee
where sal>1500 and (job=’manager’ or job=’salesman’)

between operator:
between… and operator retrives a range of data b/w two values.

Select ename, sal
From emp
Where sal between  1000 and 2000

Not operation:
Select ename, sal
From employee
Where sal not between 1000 and 2000
In operator:
In operator is used to test for values in specified list
employeeno, ename, sal
from employee
where empno in (7788, 7876,7902)
select ename, job, sal
from employee
where job in(‘clerk’, ‘analyst’)
AND sal NOT in (1000,3000,5000)

Like operator:

The like operator is used to specify a search for a pattern in a column. Two symbols can be used to construct the search string
The % symbol represents any sequence of zero or more  characters
The _(dash) symbol represents any single character
select ename
from employee
where ename like ‘s%’;
select ename
from employee
where ename like ‘_’;
select ename
from employee
where deptno is not null

0 comments:

Post a Comment