mysql - Select count with left join counting from both tables -


i have following query:

select count(*) `count`, ass.date_assigned date_assigned `buyers` b left join `assignments` ass on (ass.id_buyer = b.id) 

i want count total buyers. problem appears counting of assignments well.

i've tried grouping b.id , ass.id_buyer, i've tried changing count(*) count(b.id).

nothing works. how fix counts buyers?

use count(distinct):

select count(distinct b.id) count, max(a.date_assigned) last_date_assigned buyers b inner join assignments on a.id_buyer = b.id 

i've changed left join inner join count buyers have assignments (otherwise why join assignments?). , used max(a.date_assigned) selects particular assignment date, not random date of assignments.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -