如何简单地在MySQL中水平连接多个表?(How to simply concatenate multiple tables horizontally in MySQL?)

编程入门 行业动态 更新时间:2024-10-10 19:25:20
如何简单地在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

更多推荐

本文发布于:2023-07-19 07:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1175426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   水平   简单   MySQL   simply

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!