Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL to return first two columns of a table

Is there any SQL lingo to return JUST the first two columns of a table WITHOUT knowing the field names?

Something like

SELECT Column(1), Column(2) FROM Table_Name

Or do I have to go the long way around and find out the column names first? How would I do that?

like image 787
Jez Clark Avatar asked Feb 07 '11 17:02

Jez Clark


1 Answers

You have to get the column names first. Most platforms support this:

select column_name,ordinal_position
  from information_schema.columns
 where table_schema = ...
   and table_name = ...
   and ordinal_position <= 2
like image 123
Ken Downs Avatar answered Oct 23 '22 02:10

Ken Downs