Jump to content

Query al products with category name and subcategory name


Recommended Posts

SELECT DISTINCT (a.`id_product`),
  b.`name` AS `name`,
  a.`price` AS `price`,
  a.`id_shop_default`,
  cl.`name` AS `name_subcategory`,
  cl2.`name` AS `name_category`,
  a.`wholesale_price`
FROM (
  ps_product a
  JOIN ps_category cat1 on a.id_category_default = cat1.id_category LEFT JOIN ps_category cat2 ON cat1.id_parent = cat2.id_category

  )
  LEFT JOIN `ps_product_lang` b
    ON (b.`id_product` = a.`id_product` AND b.`id_lang` = 4 AND b.`id_shop` = 1)
  JOIN `ps_product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default)
  LEFT JOIN `ps_category_lang` cl ON (sa.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default)
  LEFT JOIN `ps_category_lang` cl2 ON (cat2.id_category = cl2.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default)
  LEFT JOIN `ps_category` cat ON (sa.`id_category_default` = cat.`id_parent` )
WHERE 1 ORDER BY a.`id_product`;

 

 

Hello, I wanted some help on validating a query to get all the products of my DB with the category and subcategory name on each row. Im getting duplicate rows on this query so I dont know if its correct.

 

Can you please help me?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...