[英]Joining three tables based on only one key
Hi Good day everyone, 大家好,大家好
id c2
-----------
id4 5
id1 5
id3 4
id2 4
table_2 table_2
-----------
id c1
-----------
id1 5
id2 5
id3 4
id4 4
table_3 表3
-----------
id c1
-----------
id3 5
id1 5
id2 4
id4 4
After joining these three tables , I would to get as the following table. 加入这三个表后,我将得到如下表。 target
目标
----------------
id c1c2c3
----------------
id1 555
id2 544
id4 454
id3 445
If you don't mind help me , please.But my tables have only one unique key.My database is mysql 5.1. 如果您不介意请帮我。但是我的表只有一个唯一的键。我的数据库是mysql 5.1。
Try this 尝试这个
SELECT T1.ID,concat(T2.c1,T1.c2,T3.c3 ) AS C1C2C3
FROM Table1 T1 JOIN Table2 T2 On T1.id =T2.id JOIN Table3 T3 On T3.id =T1.id
ORDER BY RIGHT(T1.ID,1)
O/P: O / P:
id c1c2c3
----------------
id1 555
id2 544
id3 445
id4 454
select t1.id, concat(t2.c1,t1.c2,t3.c3 ) as 'c1c2c3' from table_1 t1 inner
join table_2 t2 inner join table_3 t3 on t2.id=t1.id
and t3.id=t1.id and t3.id=t2.id order by c1c2c3 desc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.