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...

SQL Interview Questions

1. CLICK HERE FOR QUESTIONS ON BASIC SELECT     2. CLICK HERE FOR QUESTIONS ON BASIC SELECT WITH CONDITION   3.  CLICK HERE FOR QUESTIONS FROM QSPIDERS   4. CLICK HERE FOR QUESTIONS ON FUNCTIONS   5. CLICK HERE FOR QUESTIONS ON SUBQUERIES 6. CLICK HERE FOR MORE QUESTIONS ON SQL       CLICK HERE FOR ANSWERS   Some more Online Questions.   On WIZIQ.COM  -- 66 Questions and its answers Found by Neha Abhay Kumar   On SCRIBD.COM   -- 235 Questions and its answers