The solution mentioned here is incorrect. Example:
CREATE DATABASE db1; CREATE DATABASE db2; CREATE TABLE db1.t ( id_1 INT); CREATE TABLE db2.t ( id_2 INT); SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME ='t';
This will display:
+-------------+ | COLUMN_NAME | +-------------+ | id_1 | | id_2 | +-------------+
assuming table t has two columns that are obviously not true. This query lists all the columns of the tables t in all of your databases.
Instead, you should specify which database contains table t that you want to select column names:
SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = 't' AND TABLE_SCHEMA = 'db1';
Csongor Halmai Oct 10 '16 at 3:10 2016-10-10 03:10
source share