Home > Database > Mysql Tutorial > body text

The difference between In and Where in SQL statements

PHP中文网
Release: 2017-06-21 15:58:20
Original
1762 people have browsed it

<span style="font-size: 16px; font-family: 宋体"><span class="baidu-highlight">SQL</span> 语句中In 和 Where 的含义不同。</span><br/><span style="font-size: 16px; font-family: 宋体">应用解释如下:</span><br/><br/><span style="font-size: 16px; font-family: 宋体">1、如需有条件地从表中选取、删除、更新数据时,使用Where;</span><br/><span style="font-size: 16px; font-family: 宋体">2、In只作为Where条件子句下的一个运算符,除了In之外还有Between、Like、=、>、>=、<、<=等运算符。</span><br/><span style="font-size: 16px; font-family: 宋体">下面举例说明:</span><br/><span style="font-size: 16px; font-family: 宋体">1、查询名字为A和B的学生,则语句为</span><br/><span style="font-family: 宋体"><span style="font-size: 16px">Select * from student where name in(&#39;A&#39;,&#39;B&#39;);</span><span style="font-size: 16px"><br/>.......................................................................................................................<br/></span><span style="font-size: 16px"><span class="con">where 后面是一个条件式,表示要找出满足这个条件的结果<br/>in 里面是个子查询或者给定的值<br/>比如 select * from student where Sname=&#39;张三&#39;;/*查询姓名叫张三的学生的信息*/<br/><br/>select * from student where Sname in(&#39;张三&#39;,&#39;李四&#39;);/*查询张三和李四的学生的信息*/<br/><br/>select * from student where Sname in(select Sname from sn where Sno=&#39;001&#39;);/*查询学号是001的学生信息*/</span></span><span style="font-size: 16px"><br/></span></span>
Copy after login

The above is the detailed content of The difference between In and Where in SQL statements. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template