
- 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
Inserting multiple parameter values into a single column with MySQL?
To insert multiple parameter values into a single column, use the CONCAT_WS() or CONCAT(). Let us first create a table −
mysql> create table DemoTable ( Name varchar(100), Age int, CountryName varchar(100), PersonInformation text ); Query OK, 0 rows affected (0.67 sec)
Following is the query to insert multiple parameter values into a single column. We will do this using the same INSERT command, which is used to insert records in a MySQL table −
mysql> insert into DemoTable values('John',21,'US',concat_ws('-',Name,Age,CountryName)); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris',22,'AUS',concat_ws('-',Name,Age,CountryName)); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Bob',24,'UK',concat_ws('-',Name,Age,CountryName)); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+------+-------------+-------------------+ | Name | Age | CountryName | PersonInformation | +-------+------+-------------+-------------------+ | John | 21 | US | John-21-US | | Chris | 22 | AUS | Chris-22-AUS | | Bob | 24 | UK | Bob-24-UK | +-------+------+-------------+-------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How do I insert multiple values in a column with a single MySQL query?
- Passing Multiple ids to single parameter in MySQL?
- How to concatenate two column values into a single column with MySQL. The resultant column values should be separated by hyphen
- Get multiple count in a single MySQL query for specific column values
- A single MySQL query to search multiple words from different column values
- Can we skip column when inserting into MySQL?
- Insert multiple sets of values in a single statement with MySQL?
- Multiple Inserts for a single column in MySQL?
- Insert multiple values in a temporary table with a single MySQL query?
- Fastest way to insert with multiple values in a single MySQL query?
- Update multiple rows in a single column in MySQL?
- Can we skip a column name while inserting values in MySQL?
- How to insert only a single column into a MySQL table with Java?
- Concatenate the column values with separate text in MySQL and display in a single column
- Inserting multiple rows in MySQL?

Advertisements