
- 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
Is there any easy way to add multiple records in a single MySQL query?
You can easily add multiple items with only one insert command.
The syntax is as follows −
insert into yourTableName(yourColumnName1,yourColumnName2,......N) values(yourValue1,yourValue2,....N),(yourValue1,yourValue2,....N),..........N;
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value1 int, Value2 int, Value3 int ); Query OK, 0 rows affected (0.79 sec)
Insert multiple records in the table using insert command −
mysql> insert into DemoTable(Value1,Value2,Value3) values(10,20,40),(100,148,120),(150,670,1000), (100000,200000,409999); Query OK, 4 rows affected (0.17 sec) Records : 4 Duplicates : 0 Warnings : 0
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+--------+--------+ | Id | Value1 | Value2 | Value3 | +----+--------+--------+--------+ | 1 | 10 | 20 | 40 | | 2 | 100 | 148 | 120 | | 3 | 150 | 670 | 1000 | | 4 | 100000 | 200000 | 409999 | +----+--------+--------+--------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL update multiple records in a single query?
- Is there a way in MySQL to reverse a boolean field with a single query?
- Fastest way to insert with multiple values in a single MySQL query?
- Is there an easy way to rename a table in a MySQL procedure?
- In MySQL, is there a way to turn column records into a list?
- MySQL query to sort multiple columns together in a single query
- MySQL query to insert multiple records quickly
- Multiple COUNT() for multiple conditions in a single MySQL query?
- Implement multiple COUNT() in a single MySQL query
- Change multiple columns in a single MySQL query?
- 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?
- Implement multiple LIKE operators in a single MySQL query
- How to add mixed fractions in an easy way?

Advertisements