连接查询问题!!!急,在线等有两个表:表1和表2表1表2IDUserNoUserNameIDUserNo101hgc101201gqx202302ht403xs
连接查询问题!!!急,在线等
有两个表:表1和表2
表1 表2
ID UserNo UserName ID UserNo
1 01 hgc 1 01
2 01 gqx 2 02
3 02 ht
4 03 xs
我想得到表1中的UserNo未出现在表2的记录
即理想结果应该为1条:
UserNo UserName
03 xs
我是这样写SQl的: select e.UserNo,e.UserName from 表1 e,表2 d where e.UserNO<>d.UserNo;
得到的结果是:
01 hgc
01 gqx
02 ht
03 xs
03 xs
请问该SQL怎么写才能得到想要的结果?
[解决办法]
- SQL code
select * from 表1 a where not exists(select 1 from 表2 where userno=a.userno)
[解决办法]
- SQL code
select * from 表1 e where not exists (select 1 from 表2 d where e.UserNO=d.UserNo
[解决办法]
- SQL code
select * from t1 where userno not in(select userno from t2)
[解决办法]
select * from 表1 a where not exists(select 1 from 表2 b where a.UserNo =b.UserNo )
