is it possible in mysql to select a value from a table by specifying the column number instead of the column name ?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- sqlyog export query result as csv
I think for that you have to execute a single query using variables recursively. like using for loop to do that.
I don't think it is possible "directly" BUT with a query linked to the ORDINAL_POSITION field of the COLUMNS table from the information_schema should do the work!
Edit: COLUMNS table contains all the fields of all tables (and their positions)
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
, andORDER 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.