Sample on sqlfiddle -
Where I run a query like below -
select CONCAT(id, rev) as new_id from DOCS where new_id>1
i am getting below error -
Unknown column 'new_id' in 'where clause'
Why does not sql
allow to use the column alias name in the where clause. Any strong reason for that. I expect it should be smart enough to run an outer query again based on the alias
after it is done with processing/filtering/aggregation based on the original column names.
I am instead required to do the below "modified query"-
select * from (select CONCAT(id, rev) as new_id from DOCS) as t where new_id>1
Is there a better approach then the modified query.
Note: I agree -
select CONCAT(id, rev) as new_id, new_id+1 as latest_id from DOCS where new_id>1
could be little confusing to the engine, but even that seems possible.select CONCAT(id, rev) as new_id from DOCS where new_id>1 and DOCS.rev = 1
- seems confusing.
Are these the reasons or there is more to it.