加入收藏 | 设为首页 | 会员中心 | 我要投稿 衡阳站长网 (https://www.0734zz.cn/)- 数据集成、设备管理、备份、数据加密、智能搜索!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

not in 与in 做大数据的时候可以用来替换下

发布时间:2021-01-12 07:39:41 所属栏目:MySql教程 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 create table #table1 (name varchar(20),dis varchar(100))create table #table2 (name varchar(20),dis varchar(100))insert into #table1 select '

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

create table #table1 (name varchar(20),dis varchar(100))
create table #table2 (name varchar(20),dis varchar(100))

insert into #table1 select 'a','b' union select 'b','c' union select 'd','e' union select 'f','g'
insert into #table2 select 'a1','b1' union select 'b1','c1' union select 'd1','e1' union select 'f1','g1'

select * from #table2 where dis not in(select name from #table1)

select * from #table2  as a
left join #table1 as b on a.dis=b.name
where b.name is null

/*
select * from 表A where 列 not in(select 列 from 表B)

替换方法 表A 与 表B 进行join关联  让B 列为null时 则表A有数据 表B没有。
之前做数据转储的时候想到的,数据量很大的时候可以这样 效率很高

select * from 表A  as a
left join 表B as b on a.列=b.列
where b.列 is null
*/

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:衡阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读