Eléphanteau du PHP |
11 Messages
30 nov. 2022, 12:13
salam
je m'excuse pour le retard je te remercie beaucoup pour ton aide maintenant le probleme est resolu.
je veux juste me confimer si les deux methodes ci dessous sont egaux
j'ai 3 tables:
table1
id,name,indice
|1|DR |1
|2|SLIM |1
|3|BOU |2
|4|KHIR |2
|10|ZZ|22
|6|SAMIR |3
table2
id,name,indice
|1|DR |1
|2|SLIM |1
|3|BOU |2
|5|AAA|33
|6|SAMIR |3
table3
id,name,indice
|5|DR |1
|6|SLIM |1
|9|BOU |2
je veux afficher le resultat de tous les id,indices communs et non communs.
Methode1:
SELECT t1.id,t1.s1,t1.s2,t_name2.indice as s3 FROM
(SELECT t_name.id,sum(t_name.indice) AS S1,sum(t_name1.indice) AS S2 FROM `t_name` LEFT OUTER join t_name1 on t_name.id=t_name1.id GROUP BY t_name.id
UNION
SELECT t_name1.id,sum(t_name.indice)AS S1,sum(t_name1.indice) AS S2 FROM `t_name` RIGHT OUTER join t_name1 on t_name.id=t_name1.id GROUP BY t_name1.id) as t1
LEFT OUTER join t_name2 on t1.id=t_name2.id UNION
SELECT t_name2.id,t1.s1,t1.s2,t_name2.indice as s3 FROM
(SELECT t_name.id,sum(t_name.indice) AS S1,sum(t_name1.indice) AS S2 FROM `t_name` LEFT OUTER join t_name1 on t_name.id=t_name1.id GROUP BY t_name.id
UNION
SELECT t_name1.id,sum(t_name.indice)AS S1,sum(t_name1.indice) AS S2 FROM `t_name` RIGHT OUTER join t_name1 on t_name.id=t_name1.id GROUP BY t_name1.id) as t1
RIGHT OUTER join t_name2 on t1.id=t_name2.id
ORDER by id
methode2
SELECT T.id,t_name.indice as id_tname,t_name1.indice as id_tname1,t_name2.indice as id_tname2 from ((SELECT * FROM `t_name`) UNION (SELECT * FROM `t_name1`) UNION (SELECT * FROM `t_name2`) ) AS T LEFT JOIN t_name ON T.id=t_name.id left JOIN t_name1 ON T.id=t_name1.id left JOIN t_name2 ON T.id=t_name2.id
GROUP BY T.id ORDER BY T.id
Merci d'avance.