MYSQL Left Join COUNTS from multiple tables
select t.Topic, t.Title, count(distinct s.starID) as StarCount, count(distinct m.User) as UserCount, count(distinct m.messageID) as MessageCount from Topics t left join Messages m ON m.Topic = t.Topic left join Stars_Given s ON s.Topic = t.Topic group by t.Topic, t.Title Sql Fiddle Or, you can perform the aggregation in sub-queries, which will likely be more efficient if … Read more