sql - MySQL query all outcome from a table where the field's values all exist in another table -


for example, merchant(m_id), bill(b_id, m_id, payer_name) how can payer buy every merchant? used group by , compare count, bill can occur times same payer , same merchant. think need function likewhere m_id in (select m_id merchant).

there couple ways of doing this. here's 1 using subquery:

select payer_name bill  group payer_name having count(distinct m_id) = (select count(*) merchant) 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -