3

enter image description here

i want result -> Student_id,Name,Address,Marks

Thank you.

Omar Chakroun
  • 119
  • 1
  • 2
  • 12
  • Which DBMS product are you using? "SQL" is just a query language used by all relational databases, not the name of a specific database product. Please add a [tag](https://stackoverflow.com/help/tagging) for the database product you are using. [Why should I tag my DBMS](https://meta.stackoverflow.com/questions/388759/) –  Oct 05 '21 at 09:07
  • The ANSI/ISO SQL standard has INFORMATION_SCHEMA! Here you can do `select column_name from INFORMATION_SCHEMA.COLUMNS where table_name = 'Student'` . – jarlh Oct 05 '21 at 09:09
  • @Abra, my comment is mainly a response to "Metadata is not part of standard SQL", INFORMATION_SCHEMA _is_ standard SQL. (Besides, the tag says "_Answers to questions tagged with SQL should use ISO/IEC standard SQL._") – jarlh Oct 05 '21 at 09:46
  • i use Prestashop, Database/SQL Manager – Omar Chakroun Oct 05 '21 at 09:51
  • Prestashop, does that imply MySQL? – jarlh Oct 05 '21 at 09:55
  • Column names are referred to as [metadata](https://en.wikipedia.org/wiki/Metadata). While standard SQL defines [INFORMATION_SCHEMA](https://en.wikipedia.org/wiki/Information_schema), not every RDBMS implements it. However, most RDBMS's have a [data dictionary](https://en.wikipedia.org/wiki/Data_dictionary). You need to tell us which database you are using in order for us to tell you how to access the data dictionary. Are you using MySQL? Are you using SQL Server? Are you using PostgreSQL? – Abra Oct 05 '21 at 09:56
  • I don't know exactly and I use a database with Hostinger. – Omar Chakroun Oct 05 '21 at 10:24

4 Answers4

2

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
Atika
  • 1,025
  • 2
  • 6
  • 17
0

Something like this should get you the column names, if that's what you're looking for.

select *
from table
where 1=2
pd_
  • 51
  • 3
0

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

rosh-dev851
  • 534
  • 4
  • 8
0
<%

Dim rs1, i

Set rs1 = Server.CreateObject( "ADODB.Recordset" )

set rs1 = yourconnection.execute( "SELECT * FROM Student" )

For i=0 to rs1.Fields.Count-1 

      Response.Write rs1.fields(i).name  & ", "  
             
Next
 
%>

you will get: Student_id, Name, Address, Marks

Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
GenaM
  • 9
  • 3
  • 2
    This would be a good answer to "how to get column names in ASP", but the question in this case is "how to get column names in SQL" – Jortx Dec 16 '22 at 07:48
  • You are right. It's just I was looking for the same answer in ASP and when finally figured it out, decided to share it here as it's the closest question I saw. Maybe someone will find it helpful. – GenaM Dec 20 '22 at 16:01