mysql - selecting values from a table given column number

bsytKorbi picture bsytKorbi · Dec 20, 2010 · Viewed 7.8k times · Source

is it possible in mysql to select a value from a table by specifying the column number instead of the column name ?

Answer

OMG Ponies picture OMG Ponies · Dec 20, 2010

No, you can not use the ordinal value of a column in the SELECT clause.

Column order is irrelevant to a database; the ordinal value is based on the list of columns in the SELECT clause. The ordinal value is supported after the SELECT clause - IE: in the GROUP BY, and ORDER BY. That said, using ordinals is not a recommended approach because ordinals are brittle -- if someone changes the column order in the SELECT clause, the query can be negatively impacted.