Example: -Show the employees whose job title is the similar as that of employee 7566 and salary is extra than the salary of employee 7788.
Let consider the given partial relation EMP. Let us make some sub-queries for them
EMPNO
|
ENAME
|
JOB
|
SAL
|
DEPTNO
|
7566
|
Nirmal
|
MANAGER
|
2975
|
10
|
7788
|
Kailash
|
ANALYST
|
3000
|
10
|
7839
|
Karuna
|
PRESIDENT
|
5000
|
20
|
7902
|
Ashwin
|
ANALYST
|
3000
|
20
|
7905
|
Ashwini
|
MANAGER
|
4000
|
20
|
SELECT ENAME, JOB
FROM EMP
WHERE JOB = (SELECT JOB
FROM EMP
WHERE EMPPNO = 7566)
AND SAL > (SELECT SAL
FROM EMP
WHERE EMPPNO=7788);
Output: Job title for the employee 7566 occurs to be 'MANAGER')
ENAME
|
JOB
|
Ashwini
|
MANAGER
|