sql join三个表一个也许是空的

时间:2014-10-07 15:59:07

标签: mysql sql postgresql

我有三个表,两个肯定有数据值,一个值可以存在或不存在。 这是一个示例模式

Table 1
id, username

Table 2
id, street

Table 3
id, phone_number (this can be not present)

请帮我查询

1 个答案:

答案 0 :(得分:1)

SELECT t1.ID, t1.Username, t2.street, t3.phone_number 
FROM Table1 as t1
INNER JOIN Table2 as t2 on t1.id = t2.id
LEFT OUTER JOIN Table3 as t3 on t1.id = t3.id