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
Post a Comment