I'm trying to return a set of records from two tables.
I'm using LEFT OUTER JOIN
, because I want all data from table 1.
I only want the data from table 2 JOINED
if a certain clause is met.
The clause seems to be overriding the LEFT OUTER JOIN
and not returning records from table 1, if a record from table 2 doesn't meet the WHERE
clause.
SELECT p.code, p.name, d.product_code, d.detail_type, d.description
FROM products p
LEFT OUTER JOIN product_details d
ON p.code = d.product_code
WHERE product_details.detail_type = 'ALTERNATIVE NAMES'
I want all rows from products returned, but I only want rows from product_details
to be joined if product_details.detail_type = 'ALTERNATIVE NAMES'
I'm looking for some guidance as to whether this is possible or if I should be stripping out the unwanted data after the initial JOIN
?