
- 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
How to insert an array of values in a MySQL table with a single INSERT?
Let us first create a table −
mysql> create table DemoTable ( ClientId int, ClientName varchar(50) ); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command. Here, we are inserting multiple values using only a single INSERT −
mysql> insert into DemoTable values(101,'Adam'),(102,'Chris'),(103,'Robert'),(104,'Sam'),(105,'Mike'); Query OK, 5 rows affected (0.16 sec) Records: 5 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Adam | | 102 | Chris | | 103 | Robert | | 104 | Sam | | 105 | Mike | +----------+------------+ 5 rows in set (0.00 sec)
- Related Articles
- Insert multiple values in a temporary table with a single MySQL query?
- Insert multiple sets of values in a single statement with MySQL?
- How to insert only a single column into a MySQL table with Java?
- Fastest way to insert with multiple values in a single MySQL query?
- Insert all the values in a table with a single MySQL query separating records by comma
- How do I insert multiple values in a column with a single MySQL query?
- How to insert multiple rows in a table using a single INSERT command in program?
- Select and insert values with preceding zeros in a MySQL table
- Insert values in two tables with a single stored procedure call in MySQL
- Auto insert values into a MySQL table in a range?
- Insert values in a table by MySQL SELECT from another table in MySQL?
- Insert record in a MySQL table with Java
- How can I create a stored procedure to insert values in a MySQL table?
- Insert values from the first table to the second table using two SELECT statements in a single MySQL query
- How to insert multiple rows with single MySQL query?

Advertisements