I am new to SQL, I want to write a query to find the unique customers to any particular shop. For example: Shop SH1 is having 10 customers registered, out of 10 - 3 customers also registered to some other shops. I want a query which will return the unique 7 customers to shop SH1.
Both the ShopId
and CustomerId
are stored in same table, so I guess a subquery will be required.
Thanks, Mayur
Sample Data:
ShopId CustomerId
- Shop1 Cust001
- Shop1 Cust002
- Shop1 Cust003
- Shop2 Cust002
- Shop3 Cust004
- Shop4 Cust002
In above example, if I run the query for shop id Shop1, I should get Cust001, Cust003 in return which are unique to Shop1 and not Cust002 as it is linked with other shop ids.