| Question |
In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
|
Question Submitted By :: Anagha |
|
I also faced this Question!! |
Rank |
Answer Posted By |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 1 | select employee_id from employee table where department in
('a1','a2','b1','b2');
| | G.kameswara Reddy |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 2 | Select emp_id from employee where dept IN (select all
dept from employee);
| | Prasenjit_in |
| |
|
|
| |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 3 | Select emp_id from employee where dept IN (select DISTINCT
dept from employee);
| | Ab |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 4 | Select emp_id
from
employee
group by emp_id,dept
having count(*)>1;
| | Varun |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 5 | hi all i hope this answer will help you
emp
eid ename dep
001 manikandan mainframe
002 karthi java
003 jarin mainframe
001 manikandan java
003 jarin testing
004 hariharan java
001 manikandan testing
select eid from emp e1 where 1 <
(select count(*) from emp e2 where e1.eid=e2.eid)
let me know if any new answer
| | Manikandan.d |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 6 | select employee-id
from table-name
grtoup by employee-id
having count(*) > 1
| | Krishnakumar |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 7 | ans 5 need to be corrected...
subquery will fetch correct result but main query hw it
will compare... ???
it supposed to be where eid exists(select eid...where
e1.eid= e2.eid)
| | Ram.g |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 8 | Another classic example of people replying to the queries
in hurry..the answer #1, #2, #3, #4 & #7 are WRONG ANSWERS.
Answer #6 is correct. Answer #5 also seems to be correct to
me (unfortunatley I can't run & verify it at the moment,
someone please verify it & let everyone know).
Ram.g, FYI..EXISTS clause just denotes whether query after
EXISTS clause returned any row or not, it NEVER give a
count of the number of rows returned. Here need to find if
there are more than one rows (i.e count is needed) so
EXISTS can't be used here.
| | Vish |
| |
|
Re: In a single table,How to retrieve a employee-id of an
employee who works in more than one department? |
Answer
# 9 | Ans 5 is also correct but it seems a bit compliceted
| | Krishnakumar |
| |
| |