- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to concatenate all columns in MySQL?
First, you need to know how many columns are present in a table. Following is the syntax to know the column names −
show columns from yourTableName;
Following is the syntax to concatenate all columns −
select concat(yourColumnName1,yourColumnName2,yourColumnName3,........N) from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( CustomerId int, CustomerName varchar(20), CustomerAge int ); Query OK, 0 rows affected (0.66 sec)
Following is the query to know the exact column −
mysql> show columns from DemoTable;
This will produce the following output −
+--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | CustomerId | int(11) | YES | | NULL | | | CustomerName | varchar(20) | YES | | NULL | | | CustomerAge | int(11) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(101,'Chris',26); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(102,'Robert',27); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+------------+--------------+-------------+ | CustomerId | CustomerName | CustomerAge | +------------+--------------+-------------+ | 101 | Chris | 26 | | 102 | Robert | 27 | +------------+--------------+-------------+ 2 rows in set (0.00 sec)
Following is the query to concat all columns −
mysql> select concat(CustomerId,CustomerName,CustomerAge) from DemoTable;
This will produce the following output −
+---------------------------------------------+ | concat(CustomerId,CustomerName,CustomerAge) | +---------------------------------------------+ | 101Chris26 | | 102Robert27 | +---------------------------------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Concatenate two columns in MySQL?
- Concatenate all the columns in a single new column with MySQL
- Concatenate columns from different tables in MySQL
- How to concatenate all values of a single column in MySQL?
- How to display some columns (not all) in MySQL?
- How to concatenate fields in MySQL?
- How to concatenate numerical columns in an R data frame?
- Concatenate multiple rows and columns in a single row with MySQL
- How to concatenate strings from different columns and an additional string using a MySQL query?
- How to find all tables that contains two specific columns in MySQL?
- Concatenate date and time from separate columns into a single column in MySQL
- Concatenate two columns when one of such column values is null in MySQL
- Python - How to Concatenate Two or More Pandas DataFrames along columns?
- Rename all tables and columns to lower case in MySQL?
- How do I list all the columns in a MySQL table?

Advertisements