Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

mysql - Combine multiple results into 1

Suppose I have multiple queries:

SELECT col1, col2 FROM tab1;
SELECT colA, colB FROM tab2;
SELECT colTest, colBlah FROM tab3;

Every query would return only 1 result.

How can I combine those 3 results into 1?

The result would look like that:

+------+------+------+------+---------+---------+
| col1 | col2 | colA | colB | colTest | colBlah |
+------+------+------+------+---------+---------+
| abc  | def  | Ghi  | JkL  | 12A     | 42BD    |
+------+------+------+------+---------+---------+
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Join them all:

SELECT t1.col1, t1.col2, t2.colA, t2.colB, t3.colTest, t3.colBlah
FROM tab1 AS t1
CROSS JOIN tab2 AS t2
CROSS JOIN tab3 AS t3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...