I want to show two columns summarize data.
table1– count all fields that the id same as the id on theshow_userstable.table2– sum all values that the id same as the id on theshow_userstable.
This is my query:
SELECT show_users.id, COUNT(`table1`.id) as sum_fields , SUM(`table2`.count) as count_all
FROM `show_users`
LEFT JOIN `table1` ON `show_users`.id = `table1`.id
LEFT JOIN `table2` ON `show_users`.id = `table2`.id
GROUP by show_users.id
ORDER BY sum_fields DESC
The table2 results are fine, but the table1 count isn’t correct values…
Why is that?
1 Answer