MySQL: Union of a Left Join with a Right Join

前端 未结 3 393
不思量自难忘°
不思量自难忘° 2020-12-21 04:36

Say we have the following tables t1 and t2:

t1:
id | column_1
-------------
 1 |   1
 2 |   2

t2:
id | column_2
-------------
 2 |   2
 3 |   3
3条回答
  •  萌比男神i
    2020-12-21 05:20

    Try this one:

    SELECT t1.id, t1.column_1, t2.column_2 
    FROM t1 
    FULL OUTER JOIN t2 ON (t1.id = t2.id)
    

    Edit: Doesn't work, MySQL does not know FULL OUTER JOIN. Have a look here: http://www.xaprb.com/blog/2006/05/26/how-to-write-full-outer-join-in-mysql/

提交回复
热议问题