mysql - Counts from two joined tables are showing the same even though they should not be -


i have pretty straight forward query selects couple business name , counts results other 2 joined tables. reason same number of offers rules, though number correct rule.

for example have 2 offers , 6 rules. returned results show both 6.

what missing?

select     business_profile.busid,     business_profile.busname,     count(business_offers.ofr_id) cntoffers,     count(business_rules.rule_id) cntrules business_profile left join business_offers on (business_offers.ofr_busid = business_profile.busid) left join business_rules on (business_rules.rule_busid = business_profile.busid) business_profile.busid > 1 group business_profile.busid order cntrules desc, cntoffers desc  limit 20 

use distinct don't count same id multiple times.

select     business_profile.busid,     business_profile.busname,     count(distinct business_offers.ofr_id) cntoffers,     count(distinct business_rules.rule_id) cntrules 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -