MySQL - select Concat whole row

How can I select and concatenate each field in a string?

I want to do something similar to this:

SELECT concat(SELECT GROUP_CONCAT(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'tbl_name')
as single FROM tbl_name

      

.. but obviously it doesn't work. Any suggestions?

+2


source to share


2 answers


You will dynamically build your query, i.e. explicitly list all columns in concat(...)

. You can do this on the client side by running two queries or in a stored procedure using a prepared statement.



0


source


You can do it in 3 steps:

1- List of assembly fields

SELECT group_concat( column_name ) as field_list
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'TABLE_NAME'
GROUP BY table_name
LIMIT 0 , 1

      

2- Copy the value of the field_list



3 Data extraction:

SELECT CONCAT( "Paste value copied at previous step" )
FROM TABLE_NAME

      

If you create a stored procedure you can combine the above steps

0


source







All Articles