MySQL Forums
Forum List  »  Newbie

Re: Join 3 tables
Posted by: Barry Galbraith
Date: January 08, 2017 06:08PM

Does every products.id_product have an equivalent entry in table promo?

Your three table join will only return rows where there is a matching row in promo.

If you want all the products, and the promo if it exists, then you'll need a left join.

SELECT a.id_product
, a.product_name
, a.product_price
, b.photo_path
, c.percent_promo
FROM products AS a
JOIN photos AS b ON a.id_product = b.product_id
LEFT JOIN promo AS c ON a.id_product = c.product_id;

That will return every row of products and matching row from promo if it exists, or NULL if there is no match.

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
January 08, 2017 04:44PM
Re: Join 3 tables
January 08, 2017 06:08PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.