How to use INFORMATION_SCHEMA.COLUMNS Statement to Get Column Names In MySQL
Another approach to retrieve column names is by querying the INFORMATION_SCHEMA.COLUMNS table. This system table contains metadata about columns in all databases accessible to the MySQL server.
Syntax
SELECT column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = ‘write_your_tablename_here’;
Example
Alternatively, you can use the INFORMATION_SCHEMA.COLUMNS table. Here’s how:
SELECT column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'jobs';
Output:
The output contains a single column named column_name, which holds the names of columns from the jobs table. Each row in the result set represents a column name (`id`, `jobs` with columns `id `, `jobtitle` , `company` , `location` , `experienceInYear `, `salaryInLPA`, `jobdescription`) from the specified table.
How to Get Column Names in MySQL?
To get column names in MySQL use techniques such as the DESCRIBE statement, INFORMATION_SCHEMA.COLUMNS, and SHOW COLUMNS FROM commands.
Here will cover these techniques, with explained examples, and help to get a better understanding on how to get column names in MySQL.