Fyrins Posted November 10, 2017 Share Posted November 10, 2017 (edited) Bonjour à toutes et à tous, Je vous explique ma problématique : Je cherche à faire une requête SQL me permettant d'afficher une liste de produits (id, name, combination, ean13, upc) qui affiche tous mes produits, y compris ceux avec des déclinaisons. Je cherche en fait à faire des codes barres. Jusque là j'ai réussi sans problème à faire deux requêtes : la première qui extrait tous mes produits mais pas les déclinaisons SELECT `ps_product`.`id_product`, `ps_product_lang`.`name`,`ean13`,`upc` FROM `ps_product`, `ps_product_lang` WHERE `ps_product`.`id_product` = `ps_product_lang`.`id_product` La deuxième m'affiche que les produits avec déclinaisons SELECT p.id_product, pl.name, GROUP_CONCAT(DISTINCT(al.name) SEPARATOR ", ") AS combinations, p.ean13, p.upc FROM ps_product p LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product) LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product) LEFT JOIN ps_product_attribute_combination pac ON (pac.id_product_attribute = pa.id_product_attribute) LEFT JOIN ps_attribute_lang al ON (al.id_attribute = pac.id_attribute) WHERE pl.id_lang = 1 GROUP BY pac.id_product_attribute Donc ma question, existe-t-il une requête qui me permettrait de réunir ces deux requêtes ? Edited November 10, 2017 by Fyrins (see edit history) Link to comment Share on other sites More sharing options...
Fyrins Posted November 10, 2017 Author Share Posted November 10, 2017 J'ai finalement réussi grace à cette requête : SELECT p.id_product 'Product ID', pl.name 'Product Name', GROUP_CONCAT(DISTINCT(al.name) SEPARATOR ", ") AS 'Combination', p.ean13 'EAN 13', p.upc 'UPC' FROM ps_product p LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product and pl.id_lang=1) LEFT JOIN ps_category_product cp ON (p.id_product = cp.id_product) LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product) LEFT JOIN ps_stock_available s ON (p.id_product = s.id_product and pa.id_product_attribute=s.id_product_attribute) LEFT JOIN ps_product_tag pt ON (p.id_product = pt.id_product) LEFT JOIN ps_product_attribute_combination pac ON (pac.id_product_attribute = pa.id_product_attribute) LEFT JOIN ps_attribute_lang al ON (al.id_attribute = pac.id_attribute and al.id_lang=1) GROUP BY p.id_product,pac.id_product_attribute order by p.id_product 1 Link to comment Share on other sites More sharing options...
samia162 Posted June 30, 2020 Share Posted June 30, 2020 Bonjour, On est en 2020 et ta solution vient de m'épargner des heures de recherche ! Merciiiii 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now