
- 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
How to insert multiple rows with single MySQL query?
You can insert multiple rows with the help of values() separated by comma(,). The syntax is as follows −
insert into yourTableName values(value1,value2,...N),(value1,value2,...N),(value1,value2,...N),(value1,value2,...N),(value1,value2,...N),(value1,value2,...N)................N;
To insert multiple rows, let us create a table. The following is the query to create a table −
mysql> create table MultipleRowsInsert −> ( −> UserId int, −> UserName varchar(200) −> ); Query OK, 0 rows affected (1.21 sec)
Here is the query to insert multiple rows in the table −
mysql> insert into MultipleRowsInsert values(100,'Bob'),(101,'Smith'),(102,'Carol'),(104,'David'),(105,'Sam'); Query OK, 5 rows affected (0.33 sec) Records: 5 Duplicates: 0 Warnings: 0
Display all the records using the SELECT −
mysql> select *from MultipleRowsInsert;
The following is the output −
+--------+----------+ | UserId | UserName | +--------+----------+ | 100 | Bob | | 101 | Smith | | 102 | Carol | | 104 | David | | 105 | Sam | +--------+----------+ 5 rows in set (0.00 sec)
- Related Articles
- Insert multiple rows in a single MySQL query
- How to get multiple rows in a single MySQL query?
- How to obtain multiple rows in a single MySQL query?
- Fastest way to insert with multiple values in a single MySQL query?
- Insert multiple values in a temporary table with a single MySQL query?
- How do I insert multiple values in a column with a single MySQL query?
- How to insert multiple rows in a table using a single INSERT command in program?
- MySQL query to insert multiple records quickly
- Count and sort rows with a single MySQL query
- Update multiple rows in a single MongoDB query?
- MySQL query to select multiple rows effectively?
- How to multiple insert or batch insert at a time in MySQL query?
- How to insert into two tables using a single MySQL query?
- Insert multiple sets of values in a single statement with MySQL?
- MySQL query to check if multiple rows exist?

Advertisements