SQLite Forum

Select by column id
Login
As far as I know, no. There is no way that I'm aware of to say...

SELECT "the 4th column, whatever its name is" FROM table1;

You could SELECT *, and then grab the 4th column, but you can't just say "the 4th column".

If you have the column name in a variable (or table name for that matter) you'll have to use string manipulation to insert it into the SQL text. Binding only works for values. So you'll have to do something like

sql = "select " + appropriately_quote(column_name) + " from table1;"

Where appropriately_quote(column_name) is you making sure it's quoted correctly if needed. Some libraries provide tools for that, others may not. But that's where you prevent injection, handle spaces in the column name or other weird things, etc.

(I was gonna add "others please correct me if I'm wrong," but then remembered this is the internet and that's gonna happen anyway)