I'm having a little problem with the following query:
SELECT
country.country_id AS "COUNTRY_ID", count(con.medal_id) AS "GOLD"
FROM
country country
LEFT OUTER JOIN
contestant con on con.country_id = country.country_id
AND con.medal_id = 1
LEFT OUTER JOIN
event e on e.event_id = con.event_id
WHERE e.og_id = 1
GROUP BY
country.country_id
ORDER BY
country.country_id
I'm trying to get my query to display as the following:
COUNTRY_ID GOLD
---------- ----------
1 1
2 2
3 0
4 0
However, with my current query, it is showing this:
COUNTRY_ID GOLD
---------- ----------
1 1
2 2
If i change the WHERE e.og_id = 1
into AND e.go_id = 1
The results will be the following:
COUNTRY_ID GOLD
---------- ----------
1 1
2 5
3 0
4 3
This result is same as not having this line:
LEFT OUTER JOIN
event e on e.event_id = con.event_id
AND e.og_id = 1
If anyone needs more info, please let me know.
Thank you for your help.