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
1.2k views
in Technique[技术] by (71.8m points)

mysql combine query results side by side

Simple question that I cant get my head around. I want to just combine two tables with no common data side by side.

table1    table2   ->   result 
a  b       e  f          a  b  e  f
c  d       g  h          c  d  g  h
           i  j          
 
 i  j
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

You can do this using RIGHT JOIN and assign an id to each of your tables using ROW_NUMBER. See my query below:

 SELECT A.column1,A.column2,B.column1,B.column2 FROM
    (SELECT
         @row_number1:=@row_number1+1 AS RowNumber1,
         column1,
         column2
    FROM Table1, (SELECT @row_number1:=0)AS x ORDER BY column1) AS A
    RIGHT JOIN
    (SELECT
         @row_number2:=@row_number2+1 AS RowNumber2,
         column1,
         column2
    FROM Table2, (SELECT @row_number2:=0)AS y ORDER BY column1) AS B
    ON A.RowNumber1=B.RowNumber2

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

...