Re: [sqlite] SELECT alias name limitation

2014-04-28 Thread RSmith
Just to be complete - the following works for me usually to achieve what you seem to need from the first posted select: Your Select: SELECT CASE WHEN SEX='M' THEN 'MALE' WHEN SEX='F' THEN 'FEMALE' ELSE 'OTHER' END AS p, NAME||' - '||p AS 'NAME' FROM DB; The CTE version: WITH Sx(ID, Descr)

Re: [sqlite] SELECT alias name limitation

2014-04-28 Thread Petite Abeille
On Apr 28, 2014, at 9:27 PM, Staffan Tylen wrote: > (Thinking about it maybe WITH could be used, Yes, it’s a typical use case for WITH. > but that doesn't answer the first question.) One cannot refer to an identifier in the same section it was declared in, and that’s that. Therefore ‘WITH’ a

Re: [sqlite] SELECT alias name limitation

2014-04-28 Thread RSmith
It's not inconsistent at all - You cannot use an Alias in the same bit of a statement that creates the alias, but can use it freely in any next section. This is the documented behaviour at least - so it has nothing to do with "sometimes", it is quite specific. So to break down your SQL: SELECT

[sqlite] SELECT alias name limitation

2014-04-28 Thread Staffan Tylen
Why is p not valid here: SELECT CASE WHEN SEX='M' THEN 'MALE' WHEN SEX='F' THEN 'FEMALE' ELSE 'OTHER' END AS p, NAME||' - '||p AS 'NAME' FROM DB; when it's valid here: SELECT CASE WHEN SEX='M' THEN 'MALE' WHEN SEX='F' THEN 'FEMALE' ELSE 'OTHER' END AS p, NAME FROM DB ORDER BY p; Sometimes