Zhang Daniel
Zhang Daniel

Reputation: 99

SQLite no such column error to select column based on selected column

I found this weird in SQLite, if I simply select a column based on previously selected columns. The following SQL statement:

SELECT Column1 AS C1, C1 || 'something' AS C2 FROM Table1;

Will return an error in SQLite:

No such column C1

But it goes on without an error in Access.

Wondering how do I do a similar selection in SQLite? Basically I want to do this in a single SELECT instead of two SELECT.

Upvotes: 0

Views: 870

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269623

The canonical way is:

Select C1, C1 || 'something' AS C2
from (select column1 as c1, t1.*
      from Table1 t1
     ) t1

Upvotes: 1

Related Questions