Here’s my query:
$select d.*,
count(a.id) as delivered
from `dealerships` as d
left join `assignments` as a on (a.id_dealership = d.id)
group by d.id
order by d.name asc
now this works, but it is counting duplicate leads. when I add a.id_lead to the group by, it messes up everything. There is a column in the assignments table called id_lead and I want the count() (delivered) to count the total of assignments grouped by id_lead, so that it ignores more than 1 row with the same id_lead.
Is this what you mean? :
It’s the same as your query, except that instead of counting the total number of records in
a, it will only count the number of distinct non-null values ina.id_lead.(If that’s not what you mean, then please clarify.)