我正在创建一个sql命令,其中的日期存储在不同的表中,外键是借款人的id。我可以执行并输出两个表的左连接,但是如果我有三个或更多的表获取外键的数据怎么办。
这是我的SQL命令,

SELECT borrowers.firstname,
borrowers.middlename,
borrowers.lastname,
borrowers.home_address,
borrowers.date_of_birth,
borrowers.age,
borrowers.residential_status,
borrowers.status,
borrowers.date_added,
borrowersp.spouse_name,
borrowersp.date_of_birth,
borrowersp.age
FROM tblborrowers as borrowers LEFT JOIN tblborrowerspouse as borrowersp
ON borrowers.borrowers_id = borrowersp.borrowers_id
WHERE borrowers.borrowers_id=23432413;

最佳答案

通过继续联接,可以添加更多表:

FROM tblborrowers as borrowers LEFT JOIN tblborrowerspouse as borrowersp
ON borrowers.borrowers_id = borrowersp.borrowers_id
LEFT JOIN tblborrowerskid as kid
ON borrowers.borrowers_id = kid.parent_id

WHERE borrowers.borrowers_id=23432413;

你可以添加你需要的数量。

09-27 11:43