Skip to content
Advertisement

Oracle Count even if nothing is there

So i have this query:

It will return stuff from place and then d is another table describes. It will get the number of reviews the place has and the average rating. This works perfectly fine as long as there is something in the describes table. How can i go about getting the stuff that does not have anything in describes as well. Basically 0 rating or 0 reviews.

Thanks

Advertisement

Answer

Use coalesce() and LEFT JOIN:

Note how I use ON ds.pid = p.pid in the second JOIN and not ON ds.pid = d.pid like you had.

If the third relation is left-joined to the second which in turn is left-joined to the first, you lose rows from the third relation if none can be found in the second. Doesn’t make any difference in this particular case, because we have two unconditional queries on the same table – which should be simplified:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement