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');