
- 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 rows from a MySQL table and display using IN()
Let us first create a table −
mysql> create table DemoTable778 ( ClientId varchar(100), ClientName varchar(100) ); Query OK, 0 rows affected (1.05 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable778 values('J-101','John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable778 values('A-102','Adam'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable778 values('C-103','Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable778 values('D-104','David'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable778 values('R-105','Robert'); Query OK, 1 row affected (0.41 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable778;
This will produce the following output -
+----------+------------+ | ClientId | ClientName | +----------+------------+ | J-101 | John | | A-102 | Adam | | C-103 | Chris | | D-104 | David | | R-105 | Robert | +----------+------------+ 5 rows in set (0.00 sec)
Select rows from a MySQL table and display using IN() −
mysql> select *from DemoTable778 where ClientId IN('J-101','A-102','C-103','D-104','R-105');
This will produce the following output -
+----------+------------+ | ClientId | ClientName | +----------+------------+ | J-101 | John | | A-102 | Adam | | C-103 | Chris | | D-104 | David | | R-105 | Robert | +----------+------------+ 5 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL select query to select rows from a table that are not in another table?
- Randomly SELECT distinct rows in a MySQL table?
- Select rows from a table with date between 90 days ago and now in MySQL
- How to select all rows from a table except the last one in MySQL?
- Display random row from a MySQL table
- MySQL SELECT from table A that does not exist in table B using JOINS?
- Fetch random rows from a table with MySQL
- Delete more than one rows from a table using id in MySQL?
- Insert values in a table by MySQL SELECT from another table in MySQL?
- Select all rows except from today in MySQL?
- Display multiple selected rows using MySQL IN()
- How to select only 3 ordered rows on a MySQL table?
- Selecting and displaying only some rows from a column in a MySQL table
- MySQL INSERT INTO SELECT resulting in multiple rows inserted at once from another table
- Create a MySQL table from already created table selecting specific rows?
Advertisements