Logan Logan - 7 months ago 4
SQL Question

How to get just the fields from a table in MySQL?

I know you can use

DESCRIBE tablename;
to get the description of the table, which includes Field, Type, Null, Key, Default, and Extra. However, is there a way to get just the Field column and not the rest (preferably in a format that is easy to work with, like in Python for example)? I know I could do some parsing in Python, but I would prefer to get it from MySQL in the cleanest form.

I found a similar question here, but none of them answer my question.

For what it's worth, I'm interfacing with MySQL via PyMySQL in Python3 and I'm using MySQL server version 5.1.73. Thanks for your help!

Answer

As per my comment above, and your own link, and the first thing that comes to mind, how about

select column_name from INFORMATION_SCHEMA.COLUMNS
where table_schema='stackoverflow'
and table_name='questions'

my db name and table name are in the where clause