We have the query:
SELECT ID, MIN(SQRT(POW((100-x),2)) + POW((150-y),2)) AS distance
FROM cabstands
GROUP BY ID
to find out the ID of the closest point to the point 100, 150 in coordinate system. If I don’t request the ID and try to get just the distance, the query returns the true value. However, if I request the ID (as in above query) it returns all the points, because of the GROUP BY. If I don’t put GROUP BY, it simply doesn’t allow me to execute the query by saying:
ID is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
What is the solution to my problem. Thanks in advance.
You can use:
Or for MySQL: