

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- MySQL - Select all records if it contains specific number?
- MySQL query to select records beginning from a specific id
- MySQL SELECT query to return records with specific month and year
- Select random number from a specific list in MySQL?
- How to select records that begin with a specific value in MySQL?
- Retrieve from MySQL only if it contains two hyphen symbols?
- Does SELECT TOP command exist in MySQL to select limited number of records?
- How to find all tables that contains two specific columns in MySQL?
- MySQL query to select all the records only from a specific column of a table with multiple columns
- Select a field and if it's null, select another with MySQL?
- How to select sum or 0 if no records exist in MySQL?
- How select specific rows in MySQL?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- Check if ListDictionary contains a specific key in C#
- Select a fixed number of random records from a MySQL table?
Advertisements