Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Concat all columns

for example we have a table with the columns "id", "name", "type", "year". My target output would be SELECT CONCAT(id, name, type, year) FROM table.

Is it possible to do this without knowing the columns, so I can use it with every table I want without analysing its columns first? Something like CONCAT(*)?

I hope you can help me.

Thank you very much.

Regards Wulf

like image 279
Wulf Avatar asked Feb 23 '23 14:02

Wulf


2 Answers

AFAIK, you first have to know the columns. This

SHOW COLUMNS FROM table

will return all columns. Use the result to make your SELECT query.

like image 79
kasimir Avatar answered Mar 05 '23 04:03

kasimir


Check the information_schema table of MySQL, it contains meta-information concerning your tables. http://dev.mysql.com/doc/refman/5.0/en/information-schema.html

like image 29
Nanocom Avatar answered Mar 05 '23 03:03

Nanocom