In-Line Queries
Inline Queries are a type of queries that can be selected from the ‘FROM’ clause of the select statement.
Example
SELECT ENAME,DEPTNO FROM (SELECT * FROM EMP) WHERE DEPTNO=20;
The output would be:
ENAME DEPTNO
JONES 20
FORD 20
SMITH 20
SCOTT 20
ADAMS 20
The subsequent query displays the average salary of the employees along with their salary. SELECT ENAME,SAL, X “AVERAGE SALARY” ,DEPTNO FROM (SELECT AVG(SAL) X,DEPTNO B FROM EMP
GROUP BY DEPTNO),EMP WHERE DEPTNO=B;
The output would be:
ENAME SAL Average Salary DEPTNO
KING 5000 2916.6667 10
CLARK 2450 2916.6667 10
MILLER 1300 2916.6667 10
JONES 2975 2175 20
SCOTT 3000 2175 20
ADAMS 1100 2175 20
SMITH 800 2175 20
FORD 3000 2175 20
BLAKE 2850 1566.6667 30
MARTIN 1250 1566.6667 30
ALLEN 1600 1566.6667 30
TURNER 1500 1566.6667 30
JAMES 950 1566.6667 30
WARD 1250 1566.6667 30