I'm writing a program, and I have the need to SELECT column names by number, rather than by name.
That is, say the attributes to my table are:
SSN, FirstName, LastName, MiddleName, Address, City, State, Zip
How could I select the data just from columns 0 (SSN), 1 (FirstName), 2(LastName), 6 (State)
Is there a way to do this without delving into information schema?
解决方案
You should reconsider your design. A table can be changed, it can evolve, column order is very fickle. You should NOT hardcode column numbers.
ADDENDUM
By "evolve" and "fickle", I don't mean that the database engine can move them around. That's pretty much fix. No, I mean that needs can change in the future and the table design can be updated. It will be easier in the future to adapt your old code if you list the actual column names rather than the column position order. Think of column position just like row position: don't expect a particular order in the result based on input order, but rather make your query give you the order you need.