- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Use IN() to get only a particular record in a MySQL stored procedure?
Let us first create a table −
mysql> create table DemoTable2004 ( UserId varchar(20), UserName varchar(20) ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2004 values('John_123','John'); Query OK, 1 row affected (0.93 sec) mysql> insert into DemoTable2004 values('23456_Carol','Carol'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable2004 values('111_Bob','Bob'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable2004;
This will produce the following output −
+-------------+----------+ | UserId | UserName | +-------------+----------+ | John_123 | John | | 23456_Carol | Carol | | 111_Bob | Bob | +-------------+----------+ 3 rows in set (0.00 sec)
Here is the query to create a stored procedure and select only a particular record with IN() −
mysql> delimiter // mysql> create procedure test_of_in(IN uId varchar(20)) BEGIN select * from DemoTable2004 where UserId IN(uId); END // Query OK, 0 rows affected (0.15 sec) mysql> delimiter ; Call the stored procedure: mysql> call test_of_in('23456_Carol');
This will produce the following output −
+-------------+----------+ | UserId | UserName | +-------------+----------+ | 23456_Carol | Carol | +-------------+----------+ 1 row in set (0.00 sec) Query OK, 0 rows affected, 1 warning (0.02 sec)
- Related Articles
- Create a stored procedure to get the detail of a particular MySQL table stored in a database?
- How to correctly use DELIMITER in a MySQL stored procedure?
- Create a table inside a MySQL stored procedure and insert a record on calling the procedure
- How to use FOR LOOP in MySQL Stored Procedure?
- Get database name from a query implemented in a MySQL Stored Procedure?
- How to correctly use delimiter in a MySQL stored procedure and insert values?
- How to use IF in stored procedure and select in MySQL?
- Set conditions in a MySQL stored procedure
- How can we see the source code of a particular MySQL stored procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- Use delimiter correctly in a MySQL stored procedure to avoid BEGIN/END statements errors
- How to loop thrugh a stored procedure in MySQL?
- MySQL Stored Procedure to create a table?
- Implement Conditional MySQL Query in a stored procedure?
- Create a stored procedure with delimiter in MySQL

Advertisements