Here’s another MySQL tutorial of how to use an array of values while comparing in WHERE clause instead of one single value or record.
While thinking of an algorithm for comparing more than one value in WHERE clause what we get in our mind is by using OR keyword. So the easy, efficient and the shortest way instead of applying many OR operators is the one, using IN operator. Before going with the syntax lets see some scenarios in which this operator may be quite useful.
Understanding With Examples:
Lets see some explicit examples
Having the same table in the database
Check A Value In An Array:
This query gives 1 if the given value exists somewhere in the array, 0 otherwise.
SELECT 'value' IN (array)
Replacement Of More Than One OR:
This query fetches all the records from matched values in the given array. Like instead of putting many OR operators we may use IN operator. This is also useful if we need to select many records based on one single array. This is how array can be operated inside MySQL.
SELECT * FROM table WHERE column_1 LIKE character-pattern