On Apr 27, 10:35 pm, "bedla.czech" <bedla.cz...@gmail.com> wrote:
> Hi,
> I want to use calculated column alias in where clause. While I use it
> in order by clause, everything is ok.
>
> Error:
> select *, distanceEarth(lat, lon, 50.245284, 16.163576) as dist
> from location
> where dist < 50
> order by dist
>
> Workaround:
> select *, distanceEarth(lat, lon, 50.245284, 16.163576) as dist
> from location
> where distanceEarth(lat, lon, 50.245284, 16.163576) < 50
> order by dist
>
> Note: distanceEarth is custom function alias.
>
> In workaround you can see that I use calculation two times: first for
> order by clause and second for where clause.

As others have said: that's how SQL works, but there is a more elegant
workaround:

SELECT *
FROM (
   SELECT *, distanceEarth(lat, lon, 50.245284, 16.163576) as dist
   FROM location
) t
WHERE dist < 50
ORDER BY dist

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to h2-database@googlegroups.com.
To unsubscribe from this group, send email to 
h2-database+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to