求一条高效查询语句写法
有两张表,表结构一模一样
adshowlog
adid,ip,numiid,adtime,uid
adshowlog2
adid,ip,numiid,adtime,uid
想查询adshowlog2中的uid,查询条件是:adshowlog2中的ip、numiid不出现在adshowlog中
拜谢大虾
[解决办法]
--uid和IP和numiid有一项不相同的select * from adshowlog2 as a where not exists(select 1 from dshowlog where uid=a.uid and ip=a.ip and numiid=a.numiid)--uid存在,IP和numiid有一项不相同select * from adshowlog2 as a where not exists(select 1 from dshowlog where uid=a.uid and ip=a.ip and numiid=a.numiid)and exists(select 1 from dshowlog where uid=a.uid)
[解决办法]
select a2.uipfrom adshowlog a, adshowlog2 a2where a.ip <> a2.ipand a.numidd <> a2.numidd
[解决办法]
这样就行了
select * from adshowlog2 as a where not exists(select 1 from dshowlog where ip=a.ip and numiid=a.numiid)
[解决办法]
要查询不存在,一想就是not exists
大版的正解
[解决办法]
select * from adshowlog2 as a where not exists(select 1 from dshowlog where ip=a.ip and numiid=a.numiid)
[解决办法]
使用相关子查询和not exists
[解决办法]
exists的查询过程 ,只要有一条查询结果,则终止该次查询,执行下一次查询
[解决办法]
用左连接,去掉null