
- 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
MySQL Select Multiple VALUES?
To select multiple values, you can use where clause with OR and IN operator.
The syntax is as follows −
Case 1 − Using OR
select *from yourTablename where yourColumnName = value1 or yourColumnName = value2 or yourColumnName = value3,.........N;
Case 2 − Using IN
select *from yourTableName where yourColumnName IN(value1,value2,....N);
To understand the above syntax, let us create a table. The following is the query to create a table −
mysql> create table selectMultipleValues −> ( −> BookId int, −> BookName varchar(200) −> ); Query OK, 0 rows affected (1.68 sec)
Now you can insert some records in the table with the help of insert command. The query to insert records is as follows −
mysql> insert into selectMultipleValues values(100,'Introduction to C'); Query OK, 1 row affected (0.18 sec) mysql> insert into selectMultipleValues values(101,'Introduction to C++'); Query OK, 1 row affected (0.19 sec) mysql> insert into selectMultipleValues values(103,'Introduction to java'); Query OK, 1 row affected (0.14 sec) mysql> insert into selectMultipleValues values(104,'Introduction to Python'); Query OK, 1 row affected (0.14 sec) mysql> insert into selectMultipleValues values(105,'Introduction to C#'); Query OK, 1 row affected (0.13 sec) mysql> insert into selectMultipleValues values(106,'C in Depth'); Query OK, 1 row affected (0.15 sec)
Display all records from the table with the help of select statement. The query is as follows −
mysql> select *from selectMultipleValues;
The following is the output −
+--------+------------------------+ | BookId | BookName | +--------+------------------------+ | 100 | Introduction to C | | 101 | Introduction to C++ | | 103 | Introduction to java | | 104 | Introduction to Python | | 105 | Introduction to C# | | 106 | C in Depth | +--------+------------------------+ 6 rows in set (0.00 sec)
The following is the query to select multiple values with the help of OR operator.
Case 1 − Using OR operator.
mysql> select *from selectMultipleValues where BookId = 104 or BookId = 106;
The following is the output −
+--------+------------------------+ | BookId | BookName | +--------+------------------------+ | 104 | Introduction to Python | | 106 | C in Depth | +--------+------------------------+ 2 rows in set (0.00 sec)
Case 2 − Using In operator.
The following is the query to select multiple values with the help of IN operator.
mysql> select *from selectMultipleValues where BookId in(104,106);
The following is the output −
+--------+------------------------+ | BookId | BookName | +--------+------------------------+ | 104 | Introduction to Python | | 106 | C in Depth | +--------+------------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to select multiple max values which would be duplicate values as well in MYSQL?
- MySQL query to select the values having multiple occurrence and display their count
- Select multiple values with MongoDB OR operator
- MySQL select query with multiple WHERE?
- MySQL Select Statement DISTINCT for Multiple Columns?
- MySQL query to select multiple rows effectively?
- MySQL randomly select 2 values from column values?
- How to execute multiple select queries in MySQL ?
- MYSQL select DISTINCT values from two columns?
- Combine INSERT, VALUES, and SELECT in MySQL
- MySQL Select where values IN List string?
- MySQL query to get result from multiple select statements?
- Best way to combine multiple advanced MySQL select queries?
- MySQL query to fetch multiple least values?
- Select distinct values from two columns in MySQL?

Advertisements