Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
blakes
Starting Member
1 Post |
Posted - 2009-10-30 : 17:45:55
|
| Hello, new to the forums!I am needing some assistance on how one would write the following SQL correctly so that based on the queried tasks, only the one-to-one matches would return? Example Table:table:names id | name1 | Tom2 | Jack3 | Jill4 | Budtable:tasksid | task1 | Clean2 | Security3 | Manage4 | Write5 | Counter6 | Stocktable:dutytaskid | nameid1 | 11 | 32 | 12 | 23 | 23 | 33 | 46 | 16 | 46 | 3I am trying to find out WHO can "Clean"/"Stock". The answer comes back 1-Tom 3-Jill 4-Bud. I am trying to eliminate 4-Bud since he is only "Stock" and not under "Clean"? Hopefully this makes sense? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-31 : 01:28:22
|
ok. here we goSELECT n.id,n.nameFROM names nINNER JOIN (SELECT d.nameid FROM duty d INNER JOIN tasks t ON t.taskid=d.taskid WHERE t.task IN ('Clean','Stock') GROUP BY d.nameid HAVING COUNT(DISTINCT taskid)=2 )tON t.nameid=n.nameid |
 |
|
|
|
|
|