How to select only field name when using column column query in mysql

I use this query to select fields in this table. Is it possible to select only the field name, and not the entire table structure?

SHOW COLUMNS FROM student 
+7
mysql
Apr 11 2018-11-11T00:
source share
3 answers

Are you trying to determine the structure of the table? You can directly query the MySQL information_schema database for field names:

 select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='student'; 
+13
Apr 11 '11 at 4:45
source share

The solution mentioned here is incorrect. Example:

 CREATE DATABASE db1; CREATE DATABASE db2; CREATE TABLE db1.t ( id_1 INT); CREATE TABLE db2.t ( id_2 INT); SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME ='t'; 

This will display:

 +-------------+ | COLUMN_NAME | +-------------+ | id_1 | | id_2 | +-------------+ 

assuming table t has two columns that are obviously not true. This query lists all the columns of the tables t in all of your databases.

Instead, you should specify which database contains table t that you want to select column names:

 SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = 't' AND TABLE_SCHEMA = 'db1'; 
0
Oct 10 '16 at 3:10
source share

select COLUMN_NAME FROM TABLE_NAME

FOR EXAMPLE: ROLLNO is the column_name of the Student table ....

select ROLLNO from Student

-four
Apr 11 '11 at 5:18
source share



All Articles