

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fastest way to insert with multiple values in a single MySQL query?
Do not use the below query for this −
insert into yourTableName values(yourValue1,yourValue2,...N); insert into yourTableName values(yourValue1,yourValue2,...N); insert into yourTableName values(yourValue1,yourValue2,...N); . . . N
You can use below query as the fastest way to insert with multiple values in a single query −
insert into yourTableName values(yourValue1,yourValue2,...N),(yourValue1,yourValue2,...N), (yourValue1,yourValue2,...N),...................N;
Let us first create a table −
mysql> create table DemoTable1466 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> Age int -> ); Query OK, 0 rows affected (0.98 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1466(Name,Age) values('Chris',25),('David',29),('Mike',32); Query OK, 3 rows affected (0.10 sec) Records: 3 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select * from DemoTable1466;
This will produce the following output −
+----+-------+------+ | Id | Name | Age | +----+-------+------+ | 1 | Chris | 25 | | 2 | David | 29 | | 3 | Mike | 32 | +----+-------+------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Insert multiple values in a temporary table with a single MySQL query?
- How to insert multiple rows with single MySQL query?
- Insert multiple rows in a single MySQL query
- How do I insert multiple values in a column with a single MySQL query?
- Insert multiple sets of values in a single statement with MySQL?
- Use LIKE % to fetch multiple values in a single MySQL query
- Is there any easy way to add multiple records in a single MySQL query?
- A single MySQL query to search multiple words from different column values
- How to insert an array of values in a MySQL table with a single INSERT?
- MySQL select and insert in two tables with a single query
- Insert all the values in a table with a single MySQL query separating records by comma
- MySQL query to insert multiple records quickly
- Get multiple count in a single MySQL query for specific column values
- MySQL query to sort multiple columns together in a single query
- Multiple COUNT() for multiple conditions in a single MySQL query?
Advertisements