- 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
MySQL select query with multiple WHERE?
To implement multiple WHERE, use the IN() IN MySQL.
Following is the syntax:
select *from yourTableName where yourColumnName IN(yourValue1,yourValue2,...N);
Let us first create a table -
mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10,'John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(59,'Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(20,'Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(45,'David'); Query OK, 1 row affected (0.73 sec)
Display all records from the table using select statement -
mysql> select *from DemoTable;
Output
+------+-------+ | Id | Name | +------+-------+ | 10 | John | | 59 | Carol | | 20 | Sam | | 45 | David | +------+-------+ 4 rows in set (0.00 sec)
Following is the query to implement multiple WHERE -
mysql> select *from DemoTable where Id IN(59,45);
Output
+------+-------+ | Id | Name | +------+-------+ | 59 | Carol | | 45 | David | +------+-------+ 2 rows in set (0.14 sec)
- Related Articles
- MySQL query to select multiple rows effectively?
- Select multiple sums with MySQL query and display them in separate columns?
- Working with MySQL WHERE.. OR query with multiple OR usage. Is there an alternative?
- MySQL query to get result from multiple select statements?
- Multiple WHERE with LIMIT in MySQL?
- Select query with regular expression in MySQL
- Insert with a Select query in MySQL
- Update with multiple values in MySQL WHERE clause
- MySQL Select Multiple VALUES?
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- MySQL query to select the values having multiple occurrence and display their count
- Can we fetch multiple values with MySQL WHERE Clause?
- MySQL query to select records with a particular date?
- MySQL select query to fetch data with null value?
- MySQL SELECT from two tables with a single query

Advertisements