Reputation: 6757
select FIELD from (show columns FROM users)
This seems like it should work, since show columns
is displaying a table of information about the table, however. I don't really understand why this wouldn't display properly, but regardless this may not be the easiest method to extract this information.
Upvotes: 1
Views: 111
Reputation: 4190
If you're just looking for the table information you can use:
DESCRIBE users;
If you're looking to actually get the data back in a select, you can use the information_schema.columns table:
select column_name
from information_schema.columns
where table_name="users"
and table_schema = database();
Upvotes: 1
Reputation: 890
You can get the column names, types, and other meta-information from the information schema database. Example:
mysql> select column_name from information_schema.columns where table_schema='test' and table_name='t3';
+-------------+
| column_name |
+-------------+
| col1 |
| col2 |
| col3 |
| col4 |
| col5 |
+-------------+
5 rows in set (0.00 sec)
Upvotes: 5