How to use `SHOW COLUMNS` as a valid data source

I need to run the following query (this is a simplification of my process):

SELECT * 
FROM (SHOW COLUMNS FROM T1)

Bugs.

+3
source share
2 answers

This is what you want to do:

select * from (
    select * from INFORMATION_SCHEMA.COLUMNS 
    where table_name = 'T1'
) dt

You cannot use SHOW COLUMNSin a subquery, but using a table INFORMATION_SCHEMA.COLUMNS, you have much more information, and not just the column name, for example.

+6
source

See this post in SO Reverse MySQL SHOW COLUMNS

So you can probably use as in post post

SELECT * FROM (SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
 WHERE table_name = 'tablename' 
 ORDER BY column_name) colinfo
+2
source

All Articles