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
1SELECT dashboard_data.headline, dashboard_data.message, dashboard_messages.image_id, images.filename
2FROM dashboard_data
3 INNER JOIN dashboard_messages
4 ON dashboard_message_id = dashboard_messages.id
5 INNER JOIN images
6 ON dashboard_messages.image_id = images.image_id
1-- LEFT OUTER JOIN is equivalent to LEFT JOIN
2-- b.VALUE1 is null when ID not in table2 (idem for c.VALUE1 in table3)
3SELECT a.ID, a.NAME, b.VALUE1, c.VALUE1 FROM table1 a
4 LEFT OUTER JOIN table2 b ON a.ID = b.ID
5 LEFT OUTER JOIN table3 c ON a.ID = c.ID
6WHERE a.ID >= 1000;
7
8-- ⇓ Test it ⇓ (Fiddle source link)