MySQL join not returning all results
SELECT * FROM products AS p
JOIN images AS i
ON (p.id = i.product_id)
I want this query also to return results where t开发者_开发技巧here are no fields in "images" related to "products". How do I do that?
You need an OUTER
join.
SELECT *
FROM products AS p
LEFT JOIN images AS i
ON ( p.id = i.product_id )
LEFT
because you want to preserve all rows from the left (first) table.
You will need to use LEFT JOIN:
SELECT * FROM
products AS p LEFT JOIN images AS i ON p.id = i.product_id;
精彩评论