mysql get column names from table code example

Example 1: mysql get column names from table

SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='yourdatabasename' 
    AND `TABLE_NAME`='yourtablename';

Example 2: MySql get fields of table

SELECT COLUMN_NAME
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = 'my_database' AND TABLE_NAME = 'my_table';

Example 3: mysql to get column name in database

SELECT table_name, column_name from information_schema.columns WHERE column_name LIKE '%column_name_to_search%';

Example 4: how to print out column name differently in mysql

-- MySQL

SELECT column1 AS name1, column2 AS name2
FROM table1;

-- AS allows your to replace the name of a column when outputting but does not
-- actually change the column name within the database.

Tags:

Sql Example