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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select query

Author  Topic 

lemondash
Posting Yak Master

159 Posts

Posted - 2008-04-08 : 05:38:26
I have a table which has two colounms DocumentId,ProductId.

The documentId is not unique it will appera in the table for what ever productID is linked to it.

But i want to bring back the documentId's which has say for example the productID of 4,39 and 33

any ideas

Regards Lee

pravin14u
Posting Yak Master

246 Posts

Posted - 2008-04-08 : 05:39:38
select distinct documentid from tablename where Productid in(4,39,33)

Prakash.P
The secret to creativity is knowing how to hide your sources!
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-08 : 05:48:06
You want to bring documentid which is linked to all three of the productids or either of them?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2008-04-08 : 05:51:18
I tried that, but dosen't work.

Because it will look any of the values (4,39,33), but i need to bring but the ones that the documentId is equal to 4,29 and 33
Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2008-04-08 : 05:51:49
Yes. All three of the productids
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-04-08 : 05:52:54
select documentid
from tbl
where Productid in (4,39,33)
group by Productid
having count(distinct Productid) = 3

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2008-04-08 : 06:47:52
Works a dream cheers !!!!!!
Go to Top of Page
   

- Advertisement -