Checking Coma-Separated Numbers in MySQL
In a database with a table like the one provided, where NUMBERS is a comma-separated list, it's often necessary to check if specific numbers exist within that list. The LIKE %% syntax may not always be suitable for this purpose.
One effective solution is to utilize the IN operator. For example:
SELECT * FROM table WHERE 3 IN (NUMBERS) AND 15 IN (NUMBERS)
This query will select rows where both 3 and 15 are present in the NUMBERS column. The IN operator searches for a value within a comma-separated string, like the one in the NUMBERS column.
Therefore, in the provided example, only the row with ID 2 should be returned, as both 3 and 15 are found in its NUMBERS column.
The above is the detailed content of How to Check for Specific Numbers in a Comma-Separated List in MySQL?. For more information, please follow other related articles on the PHP Chinese website!