Skip to main content

Answers for SUB Queries


1. SQL> select empno, ename from emp where deptno=(select deptno from dept where dname='RESEARCH');


2. SQL> select empno, ename from emp where deptno in (select deptno from dept where loc in ('NEW YORK','CHICAGO'));

3. SQL> select dname from dept where deptno in ( select deptno from emp where job ='ANALYST');

4. SQL> select empno, ename, mgr from emp where mgr = (select empno from emp where ename='JONES');

5. SQL> select empno, ename, mgr from emp where mgr = (select mgr from emp where ename='JONES')

6. SQL> select empno, ename, job from emp where deptno in ( select deptno from dept where dname in ('SALES','ACCOUNTING'))

7. SQL> select empno, ename, job from emp where deptno in ( select deptno from dept where dname in ('SALES','RESEARCH')) and empno in (select mgr from emp)

8. SQL> select empno, ename from emp where empno not in ( select mgr from emp where mgr is not null)

9. select empno, ename from emp where empno in (select mgr from emp group by mgr
having count(*) >= 2)

10. SQL> select dname from dept where deptno in (select deptno from emp group by deptno having count(*) >=5)

11. SQL> select deptno, job, count(*) from emp where job = 'SALESMAN' group by deptno, job having count(*) >=3


12. SQL> select empno, ename, deptno from emp where empno in (select mgr from emp group by mgr
having count(*) >= 2) and deptno in (select deptno from dept where dname='RESEARCH' or dname='ACCOUNTING')

13. SQL>select max(sal) from emp where sal < (select max(sal) from emp);

14. SQL> select max(sal) from emp where sal < (select max(sal) from emp where sal < (select max(sal) from emp where sal < (select max(sal) from emp)))

Comments

Narenddra Reddy.D said…
Can you please post the answers of co-related subqueries?
Jeremia said…
sir, i think the answer to Q-11 should be
select dname from deptwhere deptno in (select deptno from emp where job='SALESMAN' group by deptno,job having count(*)>=3);
NEETISH said…
6 - ANSWER WILL BE LIKE THIS

select * from emp where deptno in ( select deptno from dept where dname in
('SALES','ACCOUNTING') AND JOB = 'MANAGER');
Anonymous said…
Can u plz give the link to download the file.
pravin said…
HI THIS IS PRAVEEN;
I HAV DONE MY GRADUATION, I HAV LEARNT ORACLE SQL AND PL/SQL .I NEED SOME QUESTIONS AND ANWERS .I HOPE SO WITH UR HELP I CAN CRACK THE INTERVIEW.
Unknown said…
List all the employees whose salaries are greater than their respective departmental average salary?
ANS:
#####
select * from emp e where sal>(select avg(sal) from emp d where d.deptno=e.deptno);
OR

SELECT empno, ename, deptno
FROM emp e
WHERE sal > (SELECT AVG(sal)
FROM emp e1
WHERE e1.deptno = e.deptno
GROUP BY deptno)
pl/sql que and ans......plz upload
14. SQL> select max(sal) from emp where sal < (select max(sal) from emp where sal < (select max(sal) from emp where sal < (select max(sal) from emp)))
......could tell me sir easy short cut query.....

Popular posts from this blog

Basics of RDBMS

Data Small set of information becomes data, this set of information helps make decision. Data is always some useful information. Database Place where you store the data. Database represents some aspect of the real world called "miniworld". A database is designed, built and populated with data for a specific purpose. It has intended group of users and some preconceived applications in which these users are interested. In other words, a database has some source from which data is derived, some degree of interaction with events in the real world and an audience that is actively interested in the contents of the database. Database can also be defined as collection of one or more tables. Ex: Mobile, human brain etc DBMS (Database Management System ) Is a program that stores retrieves and modifies data in the database on request. Study of different techniques of design, development and maintenance of the database Types of DBMS These types are based upon their m...

Installing Oracle 10g Database

Once you have downloaded the software from www.oracle.com/downloads , following steps can be used to install the software. 1. Unzip the dump downloaded from oracle.com 2. Once Unzipped, click on setup.exe to run Oracle Universal Installer Program. This will open a window as shown below.