Skip to content
Advertisement

Mysql use 2 functions in 1 query

I’m trying to use 2 same functions in 1 query which is this

This uses only the first function and give right result for the first latlngs only.

I need the row which is almost near to the 2 latlngs (the latlngs is just example don’t care if it’s wrong <3 ) I want it to Give me the row that equals the functions suppose to be the functions latlngs near for the 4 column latlngs

This is the column names.. as in the function ST_Distance_Sphere

I need something similar to this query do the same need or the fix for it <3

Advertisement

Answer

You are giving the same alias to two different columns, which makes your query ambiguous about which one you want to use to filter and order. I would recommend two different aliases and least() instead:

Note that I used a subquery rather than a having clause: this is a more standard and readable way to proceed, for no performance penalty anyway.

If you don’t need to differentiate the two computations in the resultset, you can move least() directly to the subquery:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement