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

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...