cs_plopinou
Messages postés117Date d'inscriptiondimanche 27 novembre 2005StatutMembreDernière intervention13 mai 2009
-
13 mai 2009 à 15:48
cs_plopinou
Messages postés117Date d'inscriptiondimanche 27 novembre 2005StatutMembreDernière intervention13 mai 2009
-
13 mai 2009 à 16:21
Bonjour a tous,
Je vais essaye d'etre le plus claire possible sur mon probleme.
J'ai une table test, avec 3 champs :
product_id, champs_name, value
avec des valeurs comme ceci:
1, size, 12
1, height, 15
1, weight, 100
1, color, blue
2, size, 8
2, height, 11
2, weight, 10
2, color, red
et j'aimerai bien les affichers sur une ligne par id_product c'est à dire :
1 size 12 height 15 weight 100 color blue
2 size 8 height 11 weight 10 color red
MAis voila au lieu d'avoir 2 resultat dans ma requete j'en ai 24.
Voici ma requete :
SELECT DISTINCT t1. * , t2. * , t3. * , t4. *
FROM product p
LEFT JOIN test AS t1 ON ( t1.product_id = p.id )
LEFT JOIN test AS t2 ON ( p.id = t2.product_id )
LEFT JOIN test AS t3 ON ( p.id = t3.product_id )
LEFT JOIN test AS t4 ON ( p.id = t4.product_id )
HAVING
t1.champs_name, <> t2.champs_name
AND t1.champs_name <> t3.champs_name
AND t1.champs_name <> t4.champs_name
AND t2.champs_name <> t3.champs_name
AND t2.champs_name <> t4.champs_name
AND t3.champs_name <> t4.champs_name
ORDER BY p.id
Ou est mon erreur? j'ai l'impression que le disctinct ne fonctionne pas
car le resultat que j'obtient dans 24 ligne c'est juste les element qui
change de place exemple :
cs_plopinou
Messages postés117Date d'inscriptiondimanche 27 novembre 2005StatutMembreDernière intervention13 mai 2009 13 mai 2009 à 16:21
Voici la solution :)
SELECTDISTINCT t1. * , t2. * , t3. * , t4. *
FROM product p
LEFTJOIN test AS t1 ON
(
t1.product_id = p.id
)
LEFTJOIN test AS t2 ON
(
p.id = t2.product_id AND
t1.champs_name <> t2.field_name
)
LEFTJOIN test AS t3 ON
(
p.id = t3.product_id AND
t1.champs_name <> t3.champs_name AND
t2.champs_name <> t3.champs_name
)
LEFTJOIN test AS t4 ON
(
p.id = t4.product_id AND
t1.champs_name <> t4.champs_name AND
t2.champs_name <> t4.champs_name AND
t3.champs_name <> t4.champs_name
)