How to group by having the same id?

Posted by simpatico on Stack Overflow See other posts from Stack Overflow or by simpatico
Published on 2010-06-11T15:38:18Z Indexed on 2010/06/11 15:42 UTC
Read the original article Hit count: 160

Filed under:
|

Hello,

I want the customerid who bought product X and Y and Z, from the following schema:

Sales(customerid, productName, rid);

I could do the intersection:

select customerid from sales where productName='X' 
INTERSECT 
select customerid from sales where productName='X' 
INTERSTECT
select customerid from sales where productName='Z'

Is this the best I could do?

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql