GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 86 of 171    Print  
SQL Queries- Say for Eg.
Two Tables - EMP and Dept
EMP Tables consist of Empno, Deptno, Mgrid, Empname, Location
Dept Table Consist of Deptno, Deptname.

1. Write a query to select Department name for which there is more that 20 employees in a specific Department. List the deptname and no of employees.
Deptno in Emp table is the primary key for deptno column in Dept Table.

2. Write a query to select Manager name for each employee. MGRID column in the emp table is the empid of the Manager. There should be self join query on the emp table.


  
Total Answers and Comments: 13 Last Update: August 09, 2006     Asked by: sbagai2001 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
June 06, 2006 15:50:46   #1  
Nitin        

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
select d.deptname count(e.empname) from emp e dept d where e.deptno d.deptno group by deptno having count(empname) > 20;
 
Is this answer useful? Yes | No
June 08, 2006 12:45:09   #2  
einstein Member Since: June 2006   Contribution: 1    

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
select e.ename from emp e emp e1 where e.mgrid e1.empid
 
Is this answer useful? Yes | No
June 12, 2006 02:22:05   #3  
aditi        

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
select count(empno)total dept_name
from emp dept
where emp.dept_no dept.dept_no
group by dept_name
having total>20;

 
Is this answer useful? Yes | No
June 14, 2006 02:53:06   #4  
Jegadeesan        

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
It won't work Nitin.
 
Is this answer useful? Yes | No
June 29, 2006 15:32:53   #5  
sbagai2001 Member Since: May 2006   Contribution: 19    

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
This won't work aditi. There is no column called total in these two tables.
 
Is this answer useful? Yes | No
July 13, 2006 12:42:54   #6  
ananta Member Since: June 2006   Contribution: 5    

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
select d.deptname count(d.deptno) from emp e dept d where e.deptno d.deptno group by d.deptno having count(d.deptno) > 20;
 
Is this answer useful? Yes | No
July 13, 2006 12:46:45   #7  
ananta Member Since: June 2006   Contribution: 5    

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
select e.empname from emp e emp e1 where e.empno e1.mgrid;
 
Is this answer useful? Yes | No
July 13, 2006 15:03:34   #8  
ananta Member Since: June 2006   Contribution: 5    

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
select e.empname from emp e emp e1 where e.empno e1.mgrid and e1.mgrid is not null;This will avoid any blanks..where the employee is himself is a manager.
 
Is this answer useful? Yes | No
July 17, 2006 16:06:28   #9  
lakshman        

RE: SQL Queries- Say for Eg.Two Tables - EMP an...
1. select d.dname count(e.empno) from dept d emp e where d.deptno e.deptno group by d.dname having count(empno) > 20;

2.select e.ename employee m.ename manager from emp e emp m where e.mgr m.empno ;

 
Is this answer useful? Yes | No
July 24, 2006 02:17:52   #10  
Prakash Pagam        

RE: SQL Queries- Say for Eg.Two Tables - EMP an...

select a.dname count(b.empno) from scott.emp b scott.dept a

where a.deptno b.deptno

group by a.dname b.deptno

having count(b.deptno)>1


 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape