access中有两个表 table1 table2
ID 自动编号 ID 自动编号
Name 文本 ParentID 数字
Num 数字表中的内容为
-------------------
table1 table2
ID Name ID ParentID Num
1 a 1 2 13
2 b 2 4 17
3 c
4 d
5 e我对table1和table2执行如下sql语句
select table1.ID, Name, Num from table1 , table2
where table1.ID = table2.ParentID将得到如下结果:
ID Name Num
2 b 13
4 d 17--------------------------可是我想要的结果是
ID Name Num
1 a 0
2 b 13
3 c 0
4 d 17
5 e 0也就是说, 我想把table1.ID 没有对应 table2.ParentID 的记录也放到查询结果中来, 不知道怎么写这个查询语句????
ID 自动编号 ID 自动编号
Name 文本 ParentID 数字
Num 数字表中的内容为
-------------------
table1 table2
ID Name ID ParentID Num
1 a 1 2 13
2 b 2 4 17
3 c
4 d
5 e我对table1和table2执行如下sql语句
select table1.ID, Name, Num from table1 , table2
where table1.ID = table2.ParentID将得到如下结果:
ID Name Num
2 b 13
4 d 17--------------------------可是我想要的结果是
ID Name Num
1 a 0
2 b 13
3 c 0
4 d 17
5 e 0也就是说, 我想把table1.ID 没有对应 table2.ParentID 的记录也放到查询结果中来, 不知道怎么写这个查询语句????
where table1.ID in (select ParentID from table2)
SELECT table1.ID, Name, num
FROM table1 LEFT JOIN table2 ON table1.ID = table2.ParentID;