请检查以下链接中的架构。
http://s11.postimg.org/dydr5ru3n/stack.png
我想选择所有属性以及每个属性的代理和所有者。问题是,代理商和所有者的详细信息都来自同一个表,并且存在冲突。
我应该遵循什么样的解决方案?
注意:遗憾的是我无法更改数据库架构。
答案 0 :(得分:0)
SELECT oPers.first_name AS ownerFirstName
, aPers.first_name AS agentFirstName
....
FROM properties AS p
LEFT JOIN owners AS po ON p.property_id = po.property_id
LEFT JOIN people AS oPers ON po.person_id = oPers.person_id
LEFT JOIN agents AS pa ON p.property_id = pa.property_id
LEFT JOIN people AS aPers ON pa.person_id = aPers.person_id
;