MySQL Forums
Forum List  »  Newbie

Re: Using the Min() function Source provided
Posted by: Nick Roper
Date: August 07, 2004 04:41PM

Hi Jeff,

Try using your original syntax (without the MIN function), but also do the following:

1) order by the calculated value. You can do this by giving the expression an alias and then ordering by that, e.g:

Select Building.Building_Name,
sqrt(pow((342506-Building_Location.Lat_North),2)
+pow((cos(342506)*(874104-Building_Location.Long_West)),2)) AS distance
from Building inner join Building_Location on
.....
.....
group by Building_name
order by distance asc

2) use the limit clause to return just the first row:

.....
.....
group by Building_name
order by distance asc
limit 1;

The MIN function will just calculate the minimum value for each group, it won't have any effect on the number of rows returned.


Nick


--
Nick Roper

Options: ReplyQuote


Subject
Written By
Posted
Re: Using the Min() function Source provided
August 07, 2004 04:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.