SQL not in 两个表找不同的问题 100分在线等……
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/07/26 07:10:51
SQL not in 两个表找不同的问题 100分在线等……
现在有表t1,t2(结构相同)分别为
t1:t2:
a1 a2 a3 a1 a2 a3
01 张三 90 01 张三 98
02 李四 85 04 谢六 88
03 王五 89 05 陈四 87
我现在想要找出t1.a1中的值在t2.a1中没有的(仅a1列)
结果如下:
a1 a2 a3
02 李四 85
03 王五 89
我使用:
select * from t1 where a1 not in (select t1.a1 from t1,t2 where t1.a1=t2.a1)
查询结果,程序无响应……(估计记录集太多)
现在请高手写出sql语句来,或者纠正我的错误……
使用not exists不行,得出结果为空,select * from t1 where a1 not in (select a1 from t2)程序依旧无响应
现在有表t1,t2(结构相同)分别为
t1:t2:
a1 a2 a3 a1 a2 a3
01 张三 90 01 张三 98
02 李四 85 04 谢六 88
03 王五 89 05 陈四 87
我现在想要找出t1.a1中的值在t2.a1中没有的(仅a1列)
结果如下:
a1 a2 a3
02 李四 85
03 王五 89
我使用:
select * from t1 where a1 not in (select t1.a1 from t1,t2 where t1.a1=t2.a1)
查询结果,程序无响应……(估计记录集太多)
现在请高手写出sql语句来,或者纠正我的错误……
使用not exists不行,得出结果为空,select * from t1 where a1 not in (select a1 from t2)程序依旧无响应
![SQL not in 两个表找不同的问题 100分在线等……](/uploads/image/z/4121452-28-2.jpg?t=SQL+not+in+%E4%B8%A4%E4%B8%AA%E8%A1%A8%E6%89%BE%E4%B8%8D%E5%90%8C%E7%9A%84%E9%97%AE%E9%A2%98+100%E5%88%86%E5%9C%A8%E7%BA%BF%E7%AD%89%E2%80%A6%E2%80%A6)
select * from t1 where a1 not in (select a1 from t2)
或者
select * from t1 where not exists(select t2.a1 from t2 where t2.a1=t1.a1)
建议用not exists,比in快
或者
select * from t1 where not exists(select t2.a1 from t2 where t2.a1=t1.a1)
建议用not exists,比in快