SELECT `name` , COUNT(*) AS `count` FROM `t1`, `t2` WHERE `t2`.`id` = `t1`.`id` GROUP BY `t2`.`id`
I want to obtain the name from t1 and the number of rows in t2 where the id is the same as on t1.
I've got the above so far, however it won't return any data if there are no rows in t2 that match. I'd prefer count
to be 0 (or NULL) if there are no rows, and the name still returns.
Edit: I'd like to be able to sort by the count
descending. (or name
ASC) is that possible?