SQL如何筛选出不符合条件的记录?
有A表和B 表用A表中的身份证、姓名、部门等字段匹配B表
这很容易
但是如果找出A表中的身份证、姓名和部门等字段在B表中没有的记录
用SQL应该如何写呢?
create cursor t0 (部门 c(10),姓名 c(10),身份证 c(18)) create cursor t1 (部门 c(10),姓名 c(10),身份证 c(18)) insert into t1 values ("a","张三","123456") insert into t1 values ("b","李四","234567") insert into t1 values ("a","张二","345678") insert into t1 values ("c","刘三","456789") index on 身份证 tag sy create cursor t2 (部门 c(10),姓名 c(10),身份证 c(18)) insert into t2 values ("a","张二","345678") insert into t2 values ("a","赵一","012345") insert into t2 values ("b","李四","234567") insert into t2 values ("c","刘二","567890") * VFP 方法 set relation to 身份证 into t1 scan if not found("t1") insert into t0 values (t2.部门,t2.姓名,t2.身份证) endif endscan set relation to select t0 browse * SQL 方法 select 部门,姓名,身份证 from t2 where 身份证 not in (select 身份证 from t1)