I have a query that successfully grabs the unique products from my products table and displays them. I am trying to add an icon table into the mix, where some products can have several icons. the problem is I am trying to only use joins, and when a product has 2 icons for instance, I will get 2 rows selected for that 1 product.
Here is my sql:
SELECT p.products_image,
pd.products_name,
p.products_id,
p.products_model,
p.manufacturers_id,
p.products_price,
p2i.icons_id,
p.products_tax_class_id,
IF(s.status, s.specials_new_products_price, NULL) AS
specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) AS
final_price
FROM products p
LEFT JOIN manufacturers m
ON p.manufacturers_id = m.manufacturers_id
LEFT JOIN specials s
ON p.products_id = s.products_id
LEFT JOIN products_to_categories p2c
ON p.products_id = p2c.products_id
LEFT JOIN products_description pd
ON p.products_id = pd.products_id
LEFT JOIN products_to_icon p2i
ON p.products_id = p2i.products_id
WHERE p.products_status = '1'
AND pd.language_id = '1'
AND p2c.categories_id = '36'
Add a
GROUP BYclause at the end.If you still want all the icon ids, you can combine with
group_concatE.g.: