如果连接表中的行不存在,是否有一种避免覆盖的方法?如果最后一个连接的表行为NULL,则它可以覆盖具有相同列名的其他表字段。
SELECT * FROM books
LEFT JOIN item ON books.item_id = item.item_id
LEFT JOIN stuff ON item.item_id = stuff.item_id //Not there, haha i will override item_id!
...
答案 0 :(得分:0)
你想要FULL OUTER JOIN
... mysql不支持,所以你必须UNION
LEFT OUTER JOIN
RIGHT OUTER JOIN
SELECT * FROM books
LEFT OUTER JOIN item ON books.item_id = item.item_id
LEFT OUTER JOIN stuff ON item.item_id = stuff.item_id //Not there, haha i will override item_id!
UNION
SELECT * FROM books
RIGHT OUTER JOIN item ON books.item_id = item.item_id
RIGHT OUTER JOIN stuff ON item.item_id = stuff.item_id //Not there, haha i will override item_id!
...
http://www.sitepoint.com/understanding-sql-joins-mysql-database/