View Single Post
Old 02-18-2013, 04:41 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,244
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Sunfighter: That won't work if you has some products and/or categories that do *NOT* have any matching product_extra_categories.

He needs a LEFT JOIN in there in that case.
Code:
select
    p.product_id
    p.product_name,
    c.category_name,
    e.category_name
from
    products AS p 
    INNER JOIN categories AS C ON p.product_id = c.product_id
    LEFT JOIN product_extra_categories AS e ON p.product_id = e.product_id
;
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote