这是代码(模拟sqlite3的完全外连接):
onKeyEvent
公司表包含以下列:id,name,age,address,salary。 department表包含列:id,dept,emp_id。
问题是两个表都有id列,但我只想从公司中选择id列。我怎么能这样做?
答案 0 :(得分:1)
使用别名解决:
SELECT EMP_ID, c.id, NAME, DEPT FROM COMPANY as c LEFT OUTER JOIN DEPARTMENT as d ON c.ID = d.EMP_ID
union
SELECT EMP_ID, c.id, NAME, DEPT FROM department as d LEFT OUTER JOIN company as c ON c.ID = d.EMP_ID;
这很好地说明了完整外连接的结果:
3 Teddy
4 Mark
5 David
6 Kim
7 James
8 Kitos
9 Paul
10 James
11 James
12 James
13 James
14 James
15 James
16 James
17 James
1 1 Paul IT Billing
2 2 Allen Engineering
77 Finance
空白单元格为空。