I have two tables, product and prod_report. I want my query to return a list of product names, IDs, and URLs. If there is an "admin" report for a product, I want it to return the values from that report. Otherwise, I want null values for the report fields.
This seems to me like it should be easily done with a left join, but it's not working for me. The results only include products that have admin reports.
What am I doing wrong?
Thank you.
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.
This seems to me like it should be easily done with a left join, but it's not working for me. The results only include products that have admin reports.
What am I doing wrong?
Code:
select
prod.prod_id,
prod.name,
prod.url,
pr.rank,
pr.comment,
pr.report
from
product prod
left join prod_report pr on prod.prod_id = pr.prod_id
where
( pr.user_id = 'admin' or pr.user_id is null )
Thank you.
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.