Insert all the values in a table with a single MySQL query separating records by comma


Let us first create a table −

mysql> create table if not exists DemoTable1343
   -> (
   -> `_ClientId` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> ClientName varchar(40),
   -> ClientProjectDeadline date
   -> )ENGINE=MyISAM,AUTO_INCREMENT=1000;
Query OK, 0 rows affected (0.21 sec)

Insert some records in the table using insert command with a single query −

mysql> insert into DemoTable1343(ClientName,ClientProjectDeadline) values('Chris','2019-09-24'),('Bob','2015-12-09'),
   -> ('Mike','2017-01-20'),('Carol','2018-03-31');
Query OK, 4 rows affected (0.10 sec)
Records: 4 Duplicates: 0 Warnings: 0

Display all records from the table using select statement −

mysql> select * from DemoTable1343;

This will produce the following output −

+-----------+------------+-----------------------+
| _ClientId | ClientName | ClientProjectDeadline |
+-----------+------------+-----------------------+
|      1000 |    Chris   |            2019-09-24 |
|      1001 |     Bob    |            2015-12-09 |
|      1002 |    Mike    |            2017-01-20 |
|      1003 |   Carol    |            2018-03-31 |
+-----------+------------+-----------------------+
4 rows in set (0.00 sec)

Updated on: 05-Nov-2019

180 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements