0

Possible Duplicate:
MySQL query to get column names?

I need to query the database to get the column/field names, not to be confused with data in the table. For example, if I have a table named wp_deals that contains deal_id, deal_price, creation_date then I would want to retrieve those field names from the query and nothing else.

so query should be like this

select column_names1,column_name2,column_name3 from table_name.

Be sure it should only gives those columns names that I want, not all.

Community
  • 1
  • 1
Rana.Asif
  • 397
  • 2
  • 10

4 Answers4

1

Use the DESCRIBE command.

DESCRIBE `table_name`;
alizahid
  • 959
  • 6
  • 17
0

Do like this:

SELECT COLUMN_NAME1, COLUMN_NAME2 FROM INFORMATION_SCHEMA WHERE TABLE_NAME = 'my_table';

OR

SHOW columns FROM my-table;

Read more....

http://dev.mysql.com/doc/refman/5.0/en/columns-table.html

J.K.A.
  • 7,272
  • 25
  • 94
  • 163
0
SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='yourdatabasename' 
    AND `TABLE_NAME`='yourtablename';

Credits: @ ircmaxell

Reference: This Post

Community
  • 1
  • 1
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
0

Try this and check this link COLUMNS Table:

SELECT GROUP_CONCAT(COLUMN_NAME) 
FROM information_schema.COLUMNS 
WHERE TABLE_SCHEMA = 'dbName' AND TABLE_NAME = 'tableName';
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83