简体   繁体   English

在MySQL中,“ WHERE IN”和“ WHERE”之间有什么区别?

[英]In MySQL, what is different between “WHERE IN” and “WHERE”?

Till now I still cannot differentiate between WHERE clause and WHERE IN clause. 到目前为止,我仍然无法区分WHERE子句和WHERE IN子句。 For example, I have: 例如,我有:

Query = mysqli($mysql_connect, "SELECT * From Customer Where CustomerID IN ('CU001', 'CU002', 'CU003')");

Is this same as Query = mysql($mysql_connect, "SELECT * FROM Customer Where CustomerID = 'CU001' AND CustomerID= 'CU002' AND CustomerID='CU003')"; 是否与Query = mysql($mysql_connect, "SELECT * FROM Customer Where CustomerID = 'CU001' AND CustomerID= 'CU002' AND CustomerID='CU003')"; ?

If it the same, which one is the best practice to follow? 如果相同,那么遵循的最佳实践是什么? Thanks. 谢谢。

The WHERE clause can be combined with AND, OR and NOT operators. WHERE子句可以与AND,OR和NOT运算符结合使用。 The AND and OR operators are used to filter records based on more than one condition. AND和OR运算符用于根据多个条件过滤记录。 The AND operator displays a record if all the conditions separated by AND is TRUE but should not be used for single column as you have used in 2nd query (it will not find any record). 如果用AND分隔的所有条件都为TRUE ,则AND运算符将显示一条记录,但不应像在第二查询中使用的那样将其用于单列(它将找不到任何记录)。

The In operator finds all records which falls within specified values, like OR condition. In运算符查找属于指定值(例如OR条件)的所有记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM