How To Show Column Name in MySQL

It has been a long time using MySql, and getting the value of the fields is as simple as ABC.

Ever Imagined of using Field Names instead of Field Values

But have we ever imagined, if, in some scenario, we get to deal with the name of that table’s field, instead of the values. What if we have to print the field or column names in a row first, and then their values in the next coming rows?

How to Show Field Names ?

If we want to show the name of the fields or columns, like if there’s a table members, with the fields id, full_name, address and phone, and we want to display the field names of table members, then the following query will help:

SHOW FIELDS FROM members;

We can also use the WHERE clause in SHOW FIELDS, like if we want to display the id and name only, then the following query will help:

SHOW FIELDS FROM members
WHERE FIELD IN ('id', 'name');

Or if we dont want to display the id and address, then the following query will help:

SHOW FIELDS FROM members
WHERE FIELD NOT IN ('id', 'address');

Share with:


4 comments
  1. show FIELDS from table;
    from above query i need to filter like
    whichever fields having data ‘x’;

    can anyone pls help?

  2. The result from the selects outputs 6(Field, fields. Is it possible to select only one field from the query?

Leave a Reply

Login with:



Your email address will not be published. Required fields are marked *