SQL语句–exists与in的区别
exists与in 意思相同,语法不同
exists能取多个字段
in 只能取一个字段
in的错误使用,反例如下:
eg反例:
select * from Student
where Sname='Mimo_YY' and
mark in
(select Sno,Sname,Chinese,Math,English from Grade where sex='female')
---这里的 in(select Sno,Sname,Chinese,Math,English )select 了5个字段 【错误】
---in 只能 select 1个字段
---改成 in(select English from Grade where sex='female') 【正确】
exists的例子:
eg:
select * from Student
where Sname='Mimo_YY' and
mark exists
(select Sno,Sname,Chinese,Math,English from Grade where sex='female')
–如有错误,欢迎各位交流指正;
–如有引用,请链接本文!
本文探讨了SQL中Exists和In子句的差异,指出Exists可以用于多字段查询,而In只能处理单个字段。举例说明了在使用In时的常见错误,即尝试在一个In子句中选择多个字段,这是不正确的。正确的做法是将In子句限制为单个字段。同时,给出了Exists子句的正确用法示例。
1502

被折叠的 条评论
为什么被折叠?



