select * from t1 where phone not in (select phone from t2)
select * from t1
where not EXISTS (select phone from t2 where t1.phone =t2.phone)
create table test1 (id1 int)
create table test2 (id2 int)
insert into test1 (id1) values (1),(2),(3)
insert into test2 (id2) values (1),(2)
select id1 from test1
where id1 in (select id2 from test2)
select id1 from test1where id1 in (select id1 from test2)
单独查询 select id1 from test2 是一定会报错: 消息 207,级别 16,状态 1,第 11 行 列名 'id1' 无效。
insert into test2 (id2) values (NULL)
结果是:select id1 from test1
where id1 not in (select id2 from test2)
select * from test1
where EXISTS (select * from test2 where id2 = id1 )
select * FROM test1
where NOT EXISTS (select * from test2 where id2 = id1 )
select id1 from test1
INNER JOIN test2 ON id2 = id1
select id1 from test1
LEFT JOIN test2 ON id2 = id1
where id2 IS NULL
来源:cnblogs.com/hydor/p/5391556.html
- EOF -
推荐阅读 点击标题可跳转
看完本文有收获?请转发分享给更多人
关注「ImportNew」,提升Java技能
点赞和在看就是最大的支持❤️