如何简单地在MySQL中水平连接多个表?(How to simply concatenate multiple tables horizontally in MySQL?)
我有三张桌子A , B和C 所有三个表都包含ID1和ID2列(它们具有相同顺序的完全相同的值),而其他一些列分别表示A , B和C A_x , B_x和C_x 。
因此A包含ID1 , ID2和A_x ,依此类推。
我想简单地水平连接这三个表,以便生成的表将包含列ID1 , ID2 , A_x , B_x和C_x 。 如果我知道ID1和ID2在这三个表中完全相同,我真的需要加入吗?
I have three tables A, B and C. All three tables contain ID1 and ID2 columns (which have exact same values in same order) and some other columns say A_x, B_x and C_x, in A, B and C respectively.
Thus A contains ID1, ID2, and A_x, and so on.
I want to simply concatenate these three tables horizontally so that resulting table will contain columns ID1, ID2, A_x, B_x and C_x. Do I really need to take a join if I know that ID1 and ID2 are exactly same in these three tables?
最满意答案
SELECT a.ID1, b.ID2, a.x, b.x, c.x, < and so on > FROM a JOIN b ON a.ID1=b.ID1 AND a.ID2=b.ID2 JOIN c ON a.ID1=c.ID1 AND a.ID2=c.ID2 SELECT a.ID1, b.ID2, a.x, b.x, c.x, < and so on > FROM a JOIN b ON a.ID1=b.ID1 AND a.ID2=b.ID2 JOIN c ON a.ID1=c.ID1 AND a.ID2=c.ID2更多推荐
发布评论