Professional Documents
Culture Documents
SUBQUERIES
SUBQUERIES
A sub query in the where clause of a select statement is called as Nested sub
query.
A sub query in the FROM clause of a SELECT statement is called INLINE VIEW.
Only one order by clause implemented for the total select stmt.
SELECT Selectlist
FROM Tablename);
SYNTAX:
SELECT selectlist
Single row sub queries: These queries returns only one row from the inner
select stmt, by taking this value outer query returns more.
Q) Get the details of employees who are equally designated with Smith
Ans: SQL> SELECT Ename, Sal, Job
FROM Emp
WHERE Job = (SELECT Job
FROM Emp
WHERE Ename = UPPER('smith'))
ORDER BY Sal;
from emp
from emp
Q) Get the details of employees who joined on the same day as turner?
from emp
FROM Emp
WHERE Deptno = (SELECT Deptno
FROM Dept
Q) Get the details of all the employees who are equally designated with Smith
(Excluding Smith).
Q) Get the details of all the employees who are working in 'DALLAS'.
Q) Get the details of all the employees who are earning more than the avg
investment of 30th department?
from emp
Q) Get the details of employees whose salary is greater than the avg salary
Q) Get the details of all the employees who are equal earners to highest
investment of dept?
sel empno, ename, sal, e.deptno from emp_t e where e.sal >
(sel m.sal from emp_t m
where e.mgr=m.empno).
sel e.ename from emp_t e where exists (sel * from emp_t m where
e.mgr=m.empno).
sel e.ename from emp_t e where not exists (sel * from emp_t m where
e.mgr=m.empno)