
- 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
Can we fetch multiple values with MySQL WHERE Clause?
Yes, we can fetch, but use MySQL OR for conditions. Let us first create a −
mysql> create table DemoTable1421 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeSalary int -> ); Query OK, 0 rows affected (0.82 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Chris',10000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Bob',15000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('David',8000); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Carol',8500); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Mike',14500); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select −
mysql> select * from DemoTable1421;
This will produce the following output −
+------------+--------------+----------------+ | EmployeeId | EmployeeName | EmployeeSalary | +------------+--------------+----------------+ | 1 | Chris | 10000 | | 2 | Bob | 15000 | | 3 | David | 8000 | | 4 | Carol | 8500 | | 5 | Mike | 14500 | +------------+--------------+----------------+ 5 rows in set (0.00 sec)
Here is the query to fetch multiple values with OR −
mysql> select * from DemoTable1421 where EmployeeId=1 OR EmployeeName='David' OR EmployeeSalary=14500;
This will produce the following output −
+------------+--------------+----------------+ | EmployeeId | EmployeeName | EmployeeSalary | +------------+--------------+----------------+ | 1 | Chris | 10000 | | 3 | David | 8000 | | 5 | Mike | 14500 | +------------+--------------+----------------+ 3 rows in set (0.00 sec)
- Related Articles
- Update with multiple values in MySQL WHERE clause
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”
- How can we use ASCII() function with MySQL WHERE clause?
- How can we use CHAR_LENGTH() function with MySQL WHERE clause?
- How can we use BIN() function with MySQL WHERE clause?
- How can we use FIND_IN_SET() function with MySQL WHERE clause?
- How can we use MySQL INSTR() function with WHERE clause?
- How can we use two columns with MySQL WHERE clause?
- How can we use WHERE clause with MySQL INSERT INTO command?
- Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?
- Can we use WHERE clause inside MySQL CASE statement?
- How can we use MySQL REVERSE() function on column’s data along with WHERE clause?
- What MySQL returns when we use DISTINCT clause with the column having multiple NULL values?
- How can we simulate the MySQL INTERSECT query having WHERE clause?

Advertisements