- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements