Thank you, SQLiters, for confirmation. Yes, the set up is unusual. I have a 
table which essentially maps existing column names to the names the users want 
to see.

columnRenameTable(table, column, showAS)

The goal was to use this mapping for

SELECT table.column AS showAS FROM table;

when displaying the table.

Thank you,

Roman

________________________________________
From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of Igor Tandetnik [i...@tandetnik.org]
Sent: Monday, July 29, 2013 8:48 PM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] can column name come from a table?

On 7/29/2013 8:32 PM, Roman Fleysher wrote:
> I think the answer to my question is "NO", but may be I missed something...
>
> Can column name come from a table, i.e. from another select? Example:
>
> SELECT (SELECT columnName FROM columnNameTable WHERE condition how to select 
> limit 1)
> FROM table which has that columnName;

The answer to your question is, indeed, "NO". I mean, the query you show
is legal, but does something quite different from what you want.

> Or this is not doable within SQL and I must execute internal select 
> separately and have application compose second (external) select?

Yes. Note that your design is extremely unusual. Replace that wide table
that you want to index by column name with a narrow table having a
ColumnName column, and original column names as values. Then you can write

select Value from MyNarrowTable where ColumnName in
   (select columnName from columnNameTable ...);

--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to