
- 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
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)
- Related Articles
- Get multiple count in a single MySQL query for specific column values
- Update multiple rows in a single column in MySQL?
- Multiple COUNT() for multiple conditions in a single MySQL query?
- Select multiple columns and display in a single column in MySQL?
- Inserting multiple parameter values into a single column with MySQL?
- Perform multiple inserts with INSERT INTO SELECT and UNION in MySQL
- How to alter column type of multiple columns in a single MySQL query?
- How do I insert multiple values in a column with a single MySQL query?
- A single MySQL query to search multiple words from different column values
- How to check multiple columns for a single value in MySQL?
- Implement multiple COUNT() in a single MySQL query
- Change multiple columns in a single MySQL query?
- MySQL update multiple records in a single query?
- Insert multiple rows in a single MySQL query
- How to write a single MySQL query for displaying a value for multiple inputs?

Advertisements