I have 3 tables, like:
parent(id, name)
children(id, data, parent_id, timestamp)
table_votes(id, user_id, child_id)
I want to get all rows from children table that have a specific parent_id, showing also the count of occurences in table_votes for each one.
I try something like the following, but doesn't seem to work, I think I miss all rows from children that have no entry in table_votes
SELECT
`children`.`id`,
`children`.`data`,
`children`.`parent_id`,
`children`.`timestamp`,
COUNT(`v`.`children_id`)
FROM `children` LEFT JOIN `table_votes` `v` ON `children`.`id` = `v`.`child_id`
WHERE `children`.`parent_id` = 20 ORDER BY `timestamp` ASC
Any hints what am I doing wrong?
Thank you in advance