Sql Query [message #85378] |
Sun, 20 June 2004 20:47  |
amit goel
Messages: 20 Registered: March 2004
|
Junior Member |
|
|
Suppose table: Sales having values
Sid Product
1 A
1 B
1 C
2 A
2 B
3 A
3 B
3 C
4 B
Please help me to write a SQL statement to find out those SID who has all the products and the SID and Product list grows dynamically.in this case it should be 1 and 3.
|
|
|
Re: Sql Query [message #85391 is a reply to message #85378] |
Tue, 22 June 2004 03:06  |
hudo
Messages: 165 Registered: May 2004
|
Senior Member |
|
|
If you add to your table e.g.
Sid Product
1 C
and still want the Sid who has all products (here 1 and 3) then try this:
SELECT sid
FROM SIDTEST
GROUP BY SID
HAVING count(*) >= (SELECT COUNT(*) FROM (SELECT PRODUCT FROM SIDTEST GROUP BY PRODUCT));
|
|
|