我想FULL JOIN跟随两张桌子
FULL JOIN
表1:人员
P_Id Name 1 A 2 B 3 C 4 D 5 E
表2:发票
Id P_Id 111 3 112 3 113 1 114 1 115 15
我用这个查询:
SELECT Persons.Name, Persons.P_Id, Invoice.Id FROM Persons FULL JOIN Invoice ON Persons.P_Id=Invoice.P_Id ORDER BY Persons.Name
但这会产生一个错误
“字段列表”中的未知列“ Persons.Name”
MySQL服务器版本为5.5.19,我在Microsoft Windows7中使用了命令行客户端
内联接,右联接和左联接为我工作,但我无法执行完全联接。有什么错误,请告诉我我仍然是学生。我如何在这里执行FULL JOIN?
谢谢你!
为了FULL JOIN在mysql中进行模拟,您需要UNION两个表中的Right Join和Left Join的结果
UNION
SELECT Persons.Name, Persons.P_Id, Invoice.Id FROM Persons LEFT JOIN Invoice ON Persons.P_Id=Invoice.P_Id UNION SELECT Persons.Name, Persons.P_Id, Invoice.Id FROM Invoice LEFT JOIN Persons ON Persons.P_Id=Invoice.P_Id