1select
2 t.Topic,
3 t.Title,
4 count(distinct s.starID) as StarCount,
5 count(distinct m.User) as UserCount,
6 count(distinct m.messageID) as MessageCount
7from
8 Topics t
9 left join Messages m ON m.Topic = t.Topic
10 left join Stars_Given s ON s.Topic = t.Topic
11group by
12 t.Topic,
13 t.Title