mercredi 1 avril 2015

Get row that matches all multiple rows from another table

I have 2 tables, one table contains customer ids and a service id that the customer subscribes to. The other table contains the service id's and a service description for all types of services. What I am trying to do is print out all the customer ids from the first table that have at least 5 matching unique services. Here is what I came up with but its super hacky:


select * from customers left join services where customer.serviceid = services.sid group by servicesid having count(servicesid) >= 5;


is there a better way of doing this?


Aucun commentaire:

Enregistrer un commentaire