Mysql
無法執行 FULL OUTER JOIN
這是我的查詢。
SELECT user_record.password,user_addresses.street FROM `user_record` FULL OUTER JOIN `user_addresses` ON user_record.id=user_addresses.user_id ORDER by user_record.id
這是我在 Phpmyadmin 中執行查詢時發生的錯誤。
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN `user_addresses` ON user_record.id=user_addresses.user_id ORDER by us' at line 1
Full outer join
不支持。如果你看:https://dev.mysql.com/doc/refman/5.7/en/join.html
只有
LEFT
和RIGHT
外連接。FULL OUTER
但是,您可以使用UNION
betweenLEFT
和進行模仿RIGHT
:SELECT user_record.id AS user_id, user_record.password, user_addresses.street FROM `user_record` LEFT JOIN `user_addresses` ON user_record.id = user_addresses.user_id UNION SELECT user_addresses.user_id, user_record.password, user_addresses.street FROM `user_record` RIGHT JOIN `user_addresses` ON user_record.id = user_addresses.user_id ORDER BY user_id ;
您必須包含
user_record.id / user_addresses.user_id
在您的 select 子句中才能通過它進行排序。