mysql

Show all column names of a table MySql query

There are a lot of ways to get all the column names of a table in MySql. The simplest one is using DESCRIBE of Mysql and place table name after that.

-- First method
DESCRIBE table_name;

-- Second method
SHOW COLUMNS FROM table_name;

-- Third method
SELECT column_name
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name';

-- Get column names in a single line (comma seperated)
SELECT group_concat(column_name)
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name';

Using the code we are trying all the column names that exist in a table.

Was this helpful?