I have 3 tables: restaurants, addresses and rates. I want to have a select statement to pick up all names of the restaurants, cities where the restaurants are and average rates of that restaurants. I have written something like this:
SELECT res.name as name,
AVG(rate) as rate,
ad.city as city
FROM restaurants res
JOIN rates r
on res.id = r.restaurantid
JOIN addresses ad
on res.addressid = ad.id
GROUP BY res.name, ad.city
It works fine as long as all restaurants have at least one rate, if not, the restaurant is not in the result. How can I improve this query to get all the restaurants with their cities and average rate of that restaurants and if there is no rate for the restaurant let's say assign rate 0.0.
LEFT JOIN rates rinstead ofJOIN rates r.