
- 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
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)
- Related Articles
- Insert multiple values in a temporary table with a single MySQL query?
- A single MySQL query to insert records (not all) in the second table from the first table
- Use UNION ALL to insert records in two tables with a single query in MYSQL
- Delete records from a MySQL table with IN() in a single query
- Display all the column values in a single row separated by comma in MySQL?
- Fastest way to insert with multiple values in a single MySQL query?
- How to insert an array of values in a MySQL table with a single INSERT?
- Get values from all rows and display it a single row separated by comma with MySQL
- How do I insert multiple values in a column with a single MySQL query?
- Insert values from the first table to the second table using two SELECT statements in a single MySQL query
- Can we insert records in a MySQL table without auto_increment values?
- Add a single year to all the date records in a MySQL table column
- Find specific records from a column with comma separated values in MySQL
- Insert values in a table by MySQL SELECT from another table in MySQL?
- MySQL update multiple records in a single query?

Advertisements