[AccessD] Determine Closest Two Records for a Given Value

Josh McFarlane darsant at gmail.com
Wed Dec 7 12:43:23 CST 2005


On 12/7/05, papparuff at comcast.net <papparuff at comcast.net> wrote:
> Will this work for you?
>
> SELECT MAX(Distance) AS FoundDistance
> FROM tbl_YourTableName
> Where Distance < 5
> UNION
> SELECT MIN(Distance) AS FoundDistance
> FROM tbl_YourTableName
> Where Distance > 5
> ORDER BY FoundDistance

Yes! That works exactly! I didn't even think about UNION'ing them.

Now, the next question: Can I make a DISTINCT UNION? (IE If there is a
value at 5 can I have it only return the record once?)

--
Josh McFarlane

"Peace cannot be kept by force. It can only be achieved by understanding."
-Albert Einstein



More information about the AccessD mailing list