Multiple Inserts for a single column in MySQL?


The syntax for multiple inserts for a single column in MySQL is as follows −

INSERT INTO yourTableName(yourColumnName) values(‘yourValue1'),(‘yourValue2'),(‘yourValue3'),(‘yourValue4'),.........N;

To understand the above syntax, let us create a table. The query to create a table is as follows −

mysql> create table InsertMultipleDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> UserName varchar(10),
   -> UserRole varchar(20)
   -> ,
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (3.14 sec)

Now you can insert some records in the table using insert command. Here is the query to insert multiple values using insert command −

mysql> insert into InsertMultipleDemo(UserRole) values('Admin'),('Author'),('Driver'),('Guest');
Query OK, 4 rows affected (0.17 sec)
Records: 4 Duplicates: 0 Warnings: 0

As you can see above, 4 rows are affected.

Display all records from the table using select statement. The query is as follows −

mysql> select UserRole from InsertMultipleDemo;

The following is the output −

+----------+
| UserRole |
+----------+
| Admin    |
| Author   |
| Driver   |
| Guest    |
+----------+
4 rows in set (0.00 sec)

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements