§03 数据库查询
SQL 左外连接 LEFT JOIN
以左表为主,无匹配时右半部填 NULL——对比内连接的丢弃行为。
SQL 左外连接 LEFT JOIN
执行计划
1
SELECT student.*, sc.cid, sc.score
2
FROM student
3
LEFT JOIN sc ON student.id = sc.sid
4
5
// 执行过程
6
for each row r in student:
7
for each row s in sc:
8
if r.id == s.sid then 输出合并行
9
end for
10
if 没有匹配 then 输出 (r, NULL, NULL)
11
end for