SQLite Forum

Very Newbie Question
Login

'no such column:' error when using aliases

(1.2) By jose isaias cabrera (jicman) on 2021-07-02 13:41:13 edited from 1.1 [source]

I have this SQL that is not working:

sqlite> select 00 AS A1, 0 AS A2, A1 + A2 AS TA;
Error: no such column: A1

This one works,

sqlite> select 00 AS A1, 0 AS A2;
A1|A2
0|0

I know it's easy, but I want to be able to add A1 and A2, but I can't seem to find a way. Thanks.

josé

(2) By Larry Brasfield (larrybr) on 2021-06-29 19:17:52 in reply to 1.0 [link] [source]

select a1, a2, a1+a2 as ta from (select 0 as a1, 0 as a2);

The expression aliases are considered part of the query output, usable in grouping, sorting, and any more-outer queries.

(3) By jose isaias cabrera (jicman) on 2021-06-29 19:34:06 in reply to 2 [link] [source]

Darn it! I knew is was something so simple. Thanks, Larry.

josé

(4) By Holger J (holgerj) on 2021-06-30 13:11:22 in reply to 1.0 [link] [source]

It would be very nice if you stated what your question is about instead of classifying it as a "newbie question".

(6) By jose isaias cabrera (jicman) on 2021-07-02 13:23:28 in reply to 4 [link] [source]

It would be very nice if you stated what your question is about instead of classifying it as a "newbie question".

You're right. My apologies for the bad title. I wonder if I can change the title. And, furthermore, how long am I going to keep assigning myself the title of newbie? :-)

(5) By Larry Brasfield (larrybr) on 2021-06-30 21:31:18 in reply to 1.0 [link] [source]

I second the idea of a better thread title. Perhaps "Column aliases less visible than expected". Could you please edit your post accordingly? (That's within your power since you have a login.)

(7) By jose isaias cabrera (jicman) on 2021-07-02 13:30:12 in reply to 5 [link] [source]

... Could you please edit your post accordingly?...

Call me genie. I have granted your wish. :-)

josé