SQL not in 两个表找不同的问题 100分在线等……现在有表t1,t2(结构相同)分别为t1:t2:a1 a2 a3 a1 a2 a301 张三 90 01 张三 9802 李四 85 04 谢六 8803 王五 89 05 陈四 87我现在想要找出t1.a1中的值在t2.a1中没有

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/06 05:39:04
SQL not in 两个表找不同的问题 100分在线等……现在有表t1,t2(结构相同)分别为t1:t2:a1 a2 a3 a1 a2 a301 张三 90 01 张三 9802 李四 85 04 谢六 8803 王五 89 05 陈四 87我现在想要找出t1.a1中的值在t2.a1中没有

SQL not in 两个表找不同的问题 100分在线等……现在有表t1,t2(结构相同)分别为t1:t2:a1 a2 a3 a1 a2 a301 张三 90 01 张三 9802 李四 85 04 谢六 8803 王五 89 05 陈四 87我现在想要找出t1.a1中的值在t2.a1中没有
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)程序依旧无响应

SQL not in 两个表找不同的问题 100分在线等……现在有表t1,t2(结构相同)分别为t1:t2:a1 a2 a3 a1 a2 a301 张三 90 01 张三 9802 李四 85 04 谢六 8803 王五 89 05 陈四 87我现在想要找出t1.a1中的值在t2.a1中没有
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快