
- 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
MySQL - Select all records if it contains specific number?
To select all records with specific numbers, use the FIND_IN_SET() in MySQL.
Let us create a table −
Example
mysql> create table demo73 -> ( -> interest_id varchar(100), -> interest_name varchar(100) -> ); Query OK, 0 rows affected (1.48
Insert some records into the table with the help of insert command −
Example
mysql> insert into demo73 values("100,101,103,105","SSC"); Query OK, 1 row affected (0.34 mysql> insert into demo73 values("105,103,1005,1003,104","Computer"); Query OK, 1 row affected (0.10 mysql> insert into demo73 values("110,105,104,111","Novel"); Query OK, 1 row affected (0.31
Display records from the table using select statement −
Example
mysql> select *from demo73;
This will produce the following output −
Output
+-----------------------+---------------+ | interest_id | interest_name | +-----------------------+---------------+ | 100,101,103,105 | SSC | | 105,103,1005,1003,104 | Computer | | 110,105,104,111 | Novel | +-----------------------+---------------+ 3 rows in set (0.00
Following is the query to select all records if it contains specific number −
Example
mysql> select *from demo73 where find_in_set("103",interest_id) > 0;
This will produce the following output −
Output
+-----------------------+---------------+ | interest_id | interest_name | +-----------------------+---------------+ | 100,101,103,105 | SSC | | 105,103,1005,1003,104 | Computer | +-----------------------+---------------+ 2 rows in set (0.00 sec)
- Related Articles
- Select all records if it contains specific number in MySQL?
- MySQL query to select records beginning from a specific id
- MySQL SELECT query to return records with specific month and year
- MySQL query to select all the records only from a specific column of a table with multiple columns
- How to select records that begin with a specific value in MySQL?
- Does SELECT TOP command exist in MySQL to select limited number of records?
- Select random number from a specific list 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 to find all tables that contains two specific columns in MySQL?
- MySQL RegExp to fetch records with only a specific number of words
- How to select sum or 0 if no records exist in MySQL?
- Select records from MySQL NOW() -1 Day?
- MySQL query to select top 10 records?
- MySQL query to select bottom n records

Advertisements