Sometimes, we want to use MySQL query to get column names of a table.
In this article, we’ll look at how to use MySQL query to get column names of a table.
How to use MySQL query to get column names of a table?
To use MySQL query to get column names of a table, we can select from the INFORMATION_SCHEMA.COLUMNS
table.
For instance, we write
SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='yourdatabasename'
AND `TABLE_NAME`='yourtablename';
to select the column names of the yourtablename
table in the yourdataname
table.
COnclusion
To use MySQL query to get column names of a table, we can select from the INFORMATION_SCHEMA.COLUMNS
table.