Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...