
- 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
Passing Multiple ids to single parameter in MySQL?
To pass multiple ids to single parameter, use FIND_IN_SET(). Let us first create a table −
mysql> create table DemoTable1817 ( EmployeeName varchar(20), CountryName varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1817 values('Chris','AUS'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1817 values('David','UK'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1817 values('Bob','US'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1817;
This will produce the following output −
+--------------+-------------+ | EmployeeName | CountryName | +--------------+-------------+ | Chris | AUS| | David | UK | | Bob | US | +--------------+-------------+ 3 rows in set (0.00 sec)
Here is the query to pass multiple ids to single parameter in MySQL.
mysql> select * from DemoTable1817 where find_in_set(CountryName,'US,UK');
This will produce the following output −
+--------------+-------------+ | EmployeeName | CountryName | +--------------+-------------+ | David | UK | | Bob | US | +--------------+-------------+ 2 rows in set (0.00 sec)
- Related Articles
- Inserting multiple parameter values into a single column with MySQL?
- Order MySQL query by multiple ids?
- Parameter Passing Techniques in C/C++
- Passing empty parameter to a method in JavaScript
- How to delete multiple ids in MongoDB?
- Multiple COUNT() for multiple conditions in a single MySQL query?
- Set different IDs for records with conditions using a single MySQL query
- How to get multiple rows in a single MySQL query?
- How to obtain multiple rows in a single MySQL query?
- Multiple Inserts for a single column in MySQL?
- Implement multiple COUNT() in a single MySQL query
- Change multiple columns in a single MySQL query?
- Insert multiple rows in a single MySQL query
- MySQL update multiple records in a single query?
- How to insert multiple rows with single MySQL query?

Advertisements