i want result -> Student_id,Name,Address,Marks
Thank you.
CodePudding user response:
Something like this should get you the column names, if that's what you're looking for.
select *
from table
where 1=2
CodePudding user response:
MYSQL, MS SQL and Postgresql (thanks @christophe)
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = 'database_name'
AND TABLE_NAME = 'table_name'
PIVOT the results if you need column names in one line
CodePudding user response:
If you have several other columns and want to display some of them, then use :
SELECT Student_id, Name, Address, Marks
FROM Student
Otherwise, if you only have these 4 columns in your table, then :
SELECT *
FROM Student
If you only want the names of your columns without data, then :
SELECT * FROM Student WHERE 1=0
/*or*/
SELECT Student_id, Name, Address, Marks FROM Student WHERE 1=0