Is there a reason MySQL doesn't support FULL OUTER JOINS?

前端 未结 6 892
醉话见心
醉话见心 2020-12-29 05:42

Is there a reason MySQL doesn\'t support FULL OUTER JOINS? I\'ve tried full outer join syntax in mysql many times and it never worked, just found out its not supported by my

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 06:29

    MySQL lacks a lot of functionality that other databases have*. I think they have a pretty huge backlog of ideas and not enough developers to implement them all.

    This feature was requested in 2006 and is still not implemented. I guess it has low priority because you can work around it by combining LEFT and RIGHT OUTER JOIN with a UNION ALL. Not pleasant, but it does the trick. Change this:

    SELECT *
    FROM table1
    FULL OUTER JOIN table2
    ON table1.table2_id = table2.id
    

    to this:

    SELECT *
    FROM table1
    LEFT JOIN table2
    ON table1.table2_id = table2.id
    UNION ALL
    SELECT *
    FROM table1
    RIGHT JOIN table2
    ON table1.table2_id = table2.id
    WHERE table1.table2_id IS NULL
    

    * To be fair to MySQL, they also have some features that many other databases don't have.

提交回复
热议问题