Return all columns in MySQL table in row format

Is there a way to return all columns in a MySQL table in row format?

I would like to return something like this:

course_id, name, par, yds, mtrs , etc.

I know how to show fields / columns in a table ( SHOW FIELDS FROM course; ), however they are returned in table format.

+4
source share
3 answers
 select group_concat(column_name separator ', ') from information_schema.columns where table_name = 'course' group by table_name 
+7
source

If your DB user has access to the information schema, you can use the following:

 SELECT GROUP_CONCAT( `COLUMN_NAME` ) FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'your_database_name' AND `TABLE_NAME` = 'your_table_name' GROUP BY `TABLE_NAME` 
+2
source

SELECT GROUP_CONCAT (COLUMN_NAME, ',') FROM INFORMATION_SCHEMA. COLUMNS WHERE TABLE_NAME = 'tablename'

0
source

All Articles