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 |
|
Neon
Starting Member
13 Posts |
Posted - 2011-12-06 : 23:22:38
|
| hi looked around a while trying to do this, however i'm even mor confused than when i started and someone please tell me how i can do this, or direct me to somewhere i can find out thanksi have data as followsPTtablePID, PTID1, 11, 42, 22, 43, 74, 1 4, 4PtablePID, Name1, Pump 12, Pump 23, Pump 34, Pump 4i wish to select pumps from Ptable only when a single pump (PID), has both PTID of 1 and 4so result would bePID Name1 Pump 14 Pump 4 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-06 : 23:33:39
|
| [code]SELECT p.*FROM Ptable pINNER JOIN (SELECT PID FROM PTtable WHERE PTID IN (1,4) GROUP BY PID HAVING COUNT(DISTINCT PTID)=2 )qON q.PID = p.PID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Neon
Starting Member
13 Posts |
Posted - 2011-12-06 : 23:41:20
|
| Wow fast thanks heaps will go play around with it nowagain thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-06 : 23:46:21
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|