SQL joining 3 tables when 1 table is emty
Posted
by AdRock
on Stack Overflow
See other posts from Stack Overflow
or by AdRock
Published on 2010-03-17T13:23:44Z
Indexed on
2010/03/17
13:31 UTC
Read the original article
Hit count: 335
I am trying to write a query that connects 3 tables.
The first table is info about each festival The second table is the number of votes for each festival The third table is reviews for each festival
I want to join all 3 tables so i get all the feilds from table1, join table1 with table2 on the festivalid but i also need to count the number of records in table 3 that applys to each festival.
The first 2 tables give me a result becuase they both have data in them but table 3 is empty becuase there are no reviews yet so adding that to my query fives me no results
SELECT f.*,
v.total,
v.votes,
v.festivalid,
r.reviewcount as count
FROM festivals f
INNER
JOIN vote v
ON f.festivalid = v.festivalid
INNER
JOIN (SELECT festivalid,
count(*) as reviewcount
FROM reviews)
GROUP BY festivalid) as r
on r.festivalid = v.festivalid
© Stack Overflow or respective owner