Home > Database > Mysql Tutorial > How to Check for Specific Numbers in a Comma-Separated List in MySQL?

How to Check for Specific Numbers in a Comma-Separated List in MySQL?

Susan Sarandon
Release: 2024-11-19 11:30:03
Original
187 people have browsed it

How to Check for Specific Numbers in a Comma-Separated List in MySQL?

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)
Copy after login

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template