-3

table 1 includes employee name and their initials table 2 includes projectnumber and pmember(initials as well)

we only have to display the name of the employees so i have to use a WHERE clause, which i can't construct :( here's what i've done so far. it only returns 1 employee (correct answer is 2 employees)

select t1.name
from t1
where t1.initials IN (select t2.pmember
                     from t2
                     having count(t2.projectnumber) > 1)

thanks in advance!

M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118

4 Answers4

0

To show all emp that works on all projects, you need a distinct count like this, I think:

SELECT NAME FROM T1 WHERE INITIALS IN ( 
         SELECT PMEMBER FROM T2 HAVING DISTINCT COUNT(PROJECTNUMBER) = (
             SELECT DISTINCT COUNT(PROJECTNUMBER) FROM T2)
         GROUP BY PMEMBER)
kiks73
  • 3,718
  • 3
  • 25
  • 52
0
select t1.name
from t1
left join t2 on t1.initials = t2.pmember
group by t1.name
having sum(t2.projectnumber is null) = 0
juergen d
  • 201,996
  • 37
  • 293
  • 362
0

This query should give you the names of the members working on all projects:

SELECT T1.NAME
  FROM T1
  JOIN T2 ON T1.INITIALS = T2.PMEMBER
 GROUP BY T1.NAME
HAVING COUNT(T2.PROJECTNUMBER) = (SELECT COUNT(1) FROM T2 T2ALIAS)
agim
  • 1,841
  • 12
  • 19
0

Maybe this query helps you:

SELECT T1.NAME 
FROM T1 
INNER JOIN T2 ON T1.INITIALS = T2.PMEMBER 
HAVING COUNT(T2.PROJECTNUMBER) > 1
iubeda
  • 1
  • 1