

- 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
Display selected records from a MySQL table with IN() operator
Let us first create a table −
mysql> create table DemoTable( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(100) ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(CustomerName) values('Adam Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(CustomerName) values('Chris Brown'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(CustomerName) values('David Miller'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(CustomerName) values('Carol Taylot'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(CustomerName) values('Carol Taylor'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------------+ | Id | CustomerName | +----+--------------+ | 1 | Adam Smith | | 2 | Chris Brown | | 3 | David Miller | | 5 | Carol Taylor | +----+--------------+ 4 rows in set (0.00 sec)
Following is the query to display selected records using IN operator −
mysql> select *from DemoTable where Id IN(2,5);
This will produce the following output −
+----+--------------+ | Id | CustomerName | +----+--------------+ | 2 | Chris Brown | | 5 | Carol Taylor | +----+--------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Display table records from a stored procedure in MySQL
- Display specific table names with MySQL LIKE Operator
- MySQL query to display records from a table filtered using LIKE with multiple words?
- MySql how to display the records with latest ID in a table?
- Implement MySQL IN for 2 columns to display only selected records
- Display distinct dates in MySQL from a column with date records
- Delete all records from a table in MySQL?
- Delete records from a MySQL table with IN() in a single query
- How to use MySQL SOUNDEX() function with LIKE operator to retrieve the records from table?
- Delete all the records from a MySQL table?
- Display random row from a MySQL table
- Display month names and year from a column with date records with MySQL
- Filter dates from a table with DATE and NULL records in MySQL
- MySQL query to display the count of distinct records from a column with duplicate records
- Display an error while inserting duplicate records in a MySQL table
Advertisements