
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Select all records if it contains specific number in MySQL?
For this, use concat() along with LIKE. Following is the syntax −
select *from yourTableName where concat(',', yourColumnName, ',') like '%,yourValue,%';
Let us create a table −
mysql> create table demo49 −> ( −> id varchar(20) −> , −> first_name varchar(20) −> ); Query OK, 0 rows affected (1.45 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo49 values('4,5,6', −> 'Adam'); Query OK, 1 row affected (0.20 sec) mysql> insert into demo49 values('5,3,2','Mike'); Query OK, 1 row affected (0.19 sec) mysql> insert into demo49 values('3,4,9','Bob'); Query OK, 1 row affected (0.14 sec)
Display records from the table using select statement −
mysql> select *from demo49;
This will produce the following output −
+-------+------------+ | id | first_name | +-------+------------+ | 4,5,6 | Adam | | 5,3,2 | Mike | | 3,4,9 | Bob | +-------+------------+ 3 rows in set (0.00 sec)
Following is the query to select all records if it contains specific number −
mysql> select *from demo49 where concat(',', id, ',') like '%,4,%';
This will produce the following output −
+-------+------------+ | id | first_name | +-------+------------+ | 4,5,6 | Adam | | 3,4,9 | Bob | +-------+------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL - Select all records if it contains specific number?
- MySQL query to select records beginning from a specific id
- How to select records that begin with a specific value in MySQL?
- MySQL SELECT query to return records with specific month and year
- Select random number from a specific list in MySQL?
- Does SELECT TOP command exist in MySQL to select limited number of records?
- MySQL query to select all the records only from a specific column of a table with multiple columns
- How to find all tables that contains two specific columns in MySQL?
- How to select sum or 0 if no records exist in MySQL?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- Select a fixed number of random records from a MySQL table?
- How select specific rows in MySQL?
- How to select all records that are 10 minutes within current timestamp in MySQL?
- MySQL RegExp to fetch records with only a specific number of words
- Select records from MySQL NOW() -1 Day?

Advertisements