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 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 to share