Monday, 24 August 2015

Write a query to diplay product name whose assign many employee in product table.

Table Name: Emp

EmpIdName
1Sagar
2Raj
3Mohan
4Anand
5Tiku

Table Name:  Product

ProductIdEmpIdProductName
11Product1
21Product2
32Product3
43Product4
55Product5
63Product6

select pp.proname,pp.proid,pp.empid from
(
select t.aaa,empid from
(
select count(proid)as aaa,empid  from product as p group by p.empid
) as t where t.aaa >= 2
) as t2 left join product as pp on t2.empid = pp.empid

No comments:

Post a Comment