Wednesday, October 23, 2013

SET operatior in Oracle



SELECT Empno, Ename
FROM Emp
WHERE Deptno = 10
UNION
SELECT Empno, Ename
FROM Emp
WHERE Deptno = 30
ORDER BY 1;

SELECT Empno, Ename, Job
FROM Emp
WHERE Deptno = (SELECT Deptno
                FROM Dept
                WHERE Dname = 'SALES' ) 
UNION
SELECT Empno, Ename, Job
FROM Emp
WHERE Deptno = (SELECT Deptno
                FROM Dept
                WHERE Dname = 'ACCOUNTING')
ORDER BY 1;

SELECT Empno, Ename
FROM Emp
WHERE Deptno = 10 
UNION ALL
SELECT Empno, Ename
FROM Emp
WHERE Deptno = 30
ORDER BY 1;

SELECT Empno, Ename
FROM Emp
WHERE Deptno = 10 
INTERSECT
SELECT Empno, Ename
FROM Emp
WHERE Deptno = 30
ORDER BY 1;

SELECT Empno, Ename, Deptno
FROM Emp
WHERE Deptno = 10 
MINUS
SELECT Empno, Ename, Deptno
FROM Emp
WHERE Deptno = 30
ORDER BY 1;

SELECT Job
FROM Emp
WHERE Deptno = 20 
UNION
SELECT Job
FROM Emp
WHERE Deptno = 30;

SELECT Job
FROM Emp
WHERE Deptno = 20 
UNION
SELECT Job
FROM Emp
WHERE Deptno = 30;

SELECT Job
FROM Emp
WHERE Deptno = 20 
INTERSECT
SELECT Job
FROM Emp
WHERE Deptno = 30;

SELECT Job
FROM Emp
WHERE Deptno = 20
MINUS
SELECT Job
FROM Emp
WHERE Deptno = 10;

SELECT ROWNUM, Ename
FROM Emp
WHERE ROWNUM < 7
MINUS
SELECT ROWNUM, Ename
FROM Emp
WHERE ROWNUM < 6;

No comments:

Post a Comment

Best Blogger TipsGet Flower Effect