Reputation: 1715
Till now I still cannot differentiate between WHERE
clause and WHERE IN
clause. 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')";
?
If it the same, which one is the best practice to follow? Thanks.
Upvotes: 0
Views: 54
Reputation: 165
The WHERE clause can be combined with AND, OR and NOT operators. The AND and OR operators are used to filter records based on more than one condition. 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).
The In operator finds all records which falls within specified values, like OR condition.
Upvotes: 1