Tech Support Guy banner
Status
Not open for further replies.
1 - 3 of 3 Posts

·
Registered
Joined
·
750 Posts
Discussion Starter · #1 ·
Hi,
Does anyone know how to refer to a mysql table column using a number instead of the column's name? For example, if it is the 4th column I'd like the select query to include:
ORDER BY '$sortnumber'
and the variable $sortnumber will be the number 4.
Thanks,
Clive
 

·
Registered
Joined
·
447 Posts
Best bet IMO is to build the SQL query inside of a different language (probally whatever your program is built in).
 

·
Registered
Joined
·
6,693 Posts
Hi DrP,

In MySql, the ORDER BY part of a SELECT statement refers to the position of the field in the selection not in the table.

Example :

SELECT fieldname4, fieldname7, fieldname5 ... FROM table ORDER BY 2 ASC

The result will be sorted on ascending fieldname7.
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top