Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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)
Advertisements
