IT 관련/Database

MariaDB Full outer join

nullzone 2017. 12. 17.
반응형

MariaDB Full Join 처리  

MariaDB에서는 MySQL 과는 다르게  Full Join 은 지원하지 않는다.

그러나, 다른 방법을 통해 얼마든지 구현 가능하다.

MySQL join 내용은 MySQL Join정리(http://cirius.tistory.com/1135 )를 참조 하세요.
-- select <column> from Table A full outer join Table B on A.key = B.key where A.key is null

SELECT * 
FROM tableA a LEFT JOIN tableB b
ON a.b_id = b.b_id
UNION
SELECT * 
FROM tableA a RIGHT JOIN tableB b
ON a.b_id = b.b_id

  a_id  A_col     b_id    b_id  B_col     a_id  
------  ------  ------  ------  ------  --------
     1  a1      (NULL)  (NULL)  (NULL)    (NULL)
     2  a2           1       1  b1             1
     3  a3           2       2  b2             2
     4  a4           3       3  b3             3
     5  a5           4       4  b4             4
(NULL)  (NULL)  (NULL)       5  b5        (NULL)


-- select <column> from Table A full outer join Table B on A.key = B.key where A.key is null or B.key is null

SELECT * 
FROM tableA a LEFT JOIN tableB b
ON a.b_id = b.b_id
WHERE a.b_id IS NULL
UNION
SELECT * 
FROM tableA a RIGHT JOIN tableB b
ON a.b_id = b.b_id
WHERE a.b_id IS NULL

  a_id  A_col     b_id    b_id  B_col     a_id  
------  ------  ------  ------  ------  --------
     1  a1      (NULL)  (NULL)  (NULL)    (NULL)
(NULL)  (NULL)  (NULL)       5  b5        (NULL)








반응형

댓글