关于exists的疑问
最近在进行2000向2005转变的学习,遇到一个exists使用的问题.
在删除重复行中(有唯一ID)exists的使用和in的使用效果相同,但是在更新语句上
exists和in的效果就不同了,觉得奇怪.如下是测试代码
删除重复行的
更新行的
在删除重复行中(有唯一ID)exists的使用和in的使用效果相同,但是在更新语句上
exists和in的效果就不同了,觉得奇怪.如下是测试代码
删除重复行的
if object_id('table2')is not null drop table table2
create table table2(id int identity(1,1) primary key, name varchar(2))
insert into table2(name)
select 'a' union all
select 'a' union all
select 'b' union all
select 'c' union all
select 'c' union all
select 'd'
select * from table2
delete table2 from table2 a where exists (select 1 from table2 where name=a.name and id<a.id)
delete table2 from table2 a where name in (select name from table2 where name=a.name and id<a.id)
更新行的
if object_id('tba')is not null drop table tba
if object_id('tbb')is not null drop table tbb
create table tba(c1 varchar(10),c2 varchar(10),c3 int)
insert tba select
'str1 ','str2', null union select
'str3 ','str4', null union select
'str5 ','str6', null union select
'str7 ','str8', null
create table tbb(c1 varchar(10),c2 varchar(10))
insert tbb select
'str7 ','str8' union select
'str1 ','str3' union select
'str11 ','str22' union select
'str3 ','str4'
go
update tba
set c3=1
where c1 in(select tba.c1 from tba,tbb where tba.c1=tbb.c1 and tba.c2=tbb.c2)
update tba
set c3=1
where exists(select 1 from tba,tbb where tba.c1=tbb.c1 and tba.c2=tbb.c2)
select * from tba
...全文
相关推荐
NOT EXISTS ⇔ NOT IN ⇒ NOT NULL 问题 结果不一样 疑问 如果等效
#### 示例代码```sqlSELECT * FROM A1WHERE NOT EXISTS ( SELECT 'X' FROM aa WHERE bb.smi_cd = smi_cd);```上面的示例代码意味着
MYSQLsql语句练习和疑问解析.md
"MySQL SQL语句练习与疑问解析,主要探讨了IN和EXISTS在SQL查询中的区别、使用场景以及执行效率。"在SQL查询中,`IN` 和 `EXISTS` 是两种常用的子查询操作,它们都可以
mysql exists与not exists实例详解
在遇到疑问时,查阅文档、进行性能测试以及参与社区讨论都是获取更多知识和经验的有效途径。
安装mysql出错”A Windows service with the name MySQL already exists.“如何解决
希望这个解决方案能对你有所帮助,如果你在处理过程中有任何疑问,欢迎随时提问。
Java如何在不存在文件夹的目录下创建文件
如果有任何疑问,欢迎留言讨论。


