0

我一直无法弄清楚如何使这个查询工作。

我有一张供人们及其个人数据使用的表格。我有一张我们称之为房屋的桌子

假设这些表具有以下字段:

PEOPLE
id, code, name, lastname

HOUSES
id, codeowner, codeintermediate, codebuyer, area, numberofrooms

如果我有三列与同一张表(人)有关系,我怎样才能使左联接工作?

如果所有者、中间商和买家分开,我会使用类似的东西

"SELECT
houses.*,

owners.name AS ownersname,
intermediates.name AS intermediatesname,
buyers.lname AS buyersname
FROM houses
LEFT JOIN owners ON houses.codeowner = owners.code
LEFT JOIN intermediates ON houses.codeintermediate = intermediates.code
    LEFT JOIN buyers ON houses.codebuyer = buyers.code

但是我怎样才能用一张 PEOPLE 表来完成这项工作呢?我怎样才能使用别名等等?预先感谢您!

4

1 回答 1

1

加入人员表 3 次

SELECT
houses.*,

owners.name AS ownersname,
intermediates.name AS intermediatesname,
buyers.name AS buyersname
FROM houses
LEFT JOIN people as owners ON houses.codeowner = owners.code
LEFT JOIN people as intermediates ON houses.codeintermediate = intermediates.code
LEFT JOIN people as buyers ON houses.codebuyer = buyers.code
于 2013-08-12T09:19:47.310 回答