Reputation: 245
For example, merchant(m_id), bill(b_id, m_id, payer_name) How can I get all payer who buy from every merchant? I used group by
and compare the count, but the bill can occur times by same payer and same merchant. I think I need some function likewhere m_id in all (select m_id from merchant)
.
Upvotes: 0
Views: 35
Reputation: 62841
There are a couple ways of doing this. Here's one using a subquery:
select payer_name
from bill
group by payer_name
having count(distinct m_id) = (select count(*) from merchant)
Upvotes: 1