
- 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
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 Articles
- 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?
- MySQL SELECT from table A that does not exist in table B using JOINS?
- Delete more than one rows from a table using id in MySQL?
- Display multiple selected rows using MySQL IN()
- Check if table exist without using “select from” in MySQL?
- MySQL INSERT INTO SELECT resulting in multiple rows inserted at once from another table
- Insert values in a table by MySQL SELECT from another table in MySQL?
- Select all rows except from today in MySQL?
- How to select only 3 ordered rows on a MySQL table?
- Display random row from a MySQL table
- How to select all the data from a table using MySQL in Python?
- Fetch random rows from a table with MySQL

Advertisements