Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to SELECT same records

Status
Not open for further replies.

astralex

IS-IT--Management
Dec 11, 2009
5
SE
Hi, how can I select all prodid in the table below which are availabe in both shopid 1 and 2? The answer should be Prodid 2

Table ProdsInShops

Shopid|Prodid
______|_______
1 |1
1 |2
1 |3
2 |4
2 |2

Thank you!
 
SELECT Prodid FROM ProdsInShops GROUP BY Prodid HAVING COUNT(*)>1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry, just one more question: how do I add that I want prodid only from shopid 1 and 2?
 
SELECT Prodid FROM ProdsInShops WHERE Shopid IN (1,2) GROUP BY Prodid HAVING COUNT(*)>1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top