查询主表中关联表中没有的记录
TABLE1:
ID DATA1 FLAG
1 1 0
2 100 0
3 50 0
4 65 1
5 7 0
TABLE2:
ID ID2 DATA2
1 1 80
2 1 90
3 3 92
查询table1中所有flag值为0且没有在table2中出现的id,其中table1的id与table2的id2相对应.
问题点数:50、回复次数:4Top
1 楼Yang_(扬帆破浪)回复于 2002-07-20 17:47:16 得分 40
select * from table1
where flag=0
and id not in (
select id2 from table2
)
or:
select * from table1
where flag=0
and not exists(
select * from table2 where id2=table1.id
)
Top
2 楼OpenVMS(半知半解)回复于 2002-07-20 18:06:05 得分 10
select a.*
where a.flag=0 and len(b.id2)=0
from table1 a full join table2 b on a.id=b.idTop




