

- 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
MySQL query to find a match and fetch records
To find a match from records, use MySQL IN(). Let us first create a table −
mysql> create table DemoTable ( Id int, FirstName varchar(20), Gender ENUM('Male','Female') ); Query OK, 0 rows affected (1.73 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(1,'Chris','Male'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values(10,'Emma','Female'); Query OK, 1 row affected (1.88 sec) mysql> insert into DemoTable values(9,'Emma','Male'); Query OK, 1 row affected (0.70 sec) mysql> insert into DemoTable values(11,'Isabella','Female'); Query OK, 1 row affected (0.46 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+-----------+--------+ | Id | FirstName | Gender | +------+-----------+--------+ | 1 | Chris | Male | | 10 | Emma | Female | | 9 | Emma | Male | | 11 | Isabella | Female | +------+-----------+--------+ 4 rows in set (0.00 sec)
Following is the query to find match and fetch records with Id 1 and 11 −
mysql> select *from DemoTable where Id IN(1,11);
This will produce the following output −
+------+-----------+--------+ | Id | FirstName | Gender | +------+-----------+--------+ | 1 | Chris | Male | | 11 | Isabella | Female | +------+-----------+--------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL query to fetch records from a range of months?
- MySQL query to fetch records before currentdate + 2 weeks?
- MySQL query to fetch records where decimal is a whole number
- MySQL query for text search with LIKE and OR to fetch records
- MySQL query to fetch records wherein timestamp is before 15+ days?
- MySQL query to find alternative records from a table
- MySQL query to fetch the latest date from a table with date records
- Implement MySQL REGEXP to fetch records with . and numbers
- MySQL to fetch records based on a specific month and year?
- MongoDB query to fetch date records (ISODate format) in a range
- MySQL query to fetch specific records matched from an array (comma separated values)
- How to order records and fetch some using MySQL LIMIT?
- MySQL query to fetch date with year and month?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- Fetch records containing a specific character twice in MySQL
Advertisements