mysql - selecting values from a table given column number

耗尽温柔 提交于 2020-01-23 19:23:27

问题


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


回答1:


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.




回答2:


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)




回答3:


I think for that you have to execute a single query using variables recursively. like using for loop to do that.



来源:https://stackoverflow.com/questions/4492035/mysql-selecting-values-from-a-table-given-column-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!