Re: sql select question



hilz wrote:
....
Ok... my situation got a little more complecated now. I hope it is still
doable with one sql select
.....

Hi, I almost gave up on this one 9^) but finally have a solution.
However, its ugly (IMHO) and I cannot guarantee it works in all cases.
Here it is:

SELECT *
FROM (SELECT *
FROM chtmp
WHERE (( speed = (SELECT MAX (speed)
FROM chtmp
WHERE speed < 35)
OR speed = (SELECT MIN (speed)
FROM chtmp
WHERE speed > 35)
)
)) spd
WHERE ( spd.distance = (SELECT MAX (distance)
FROM chtmp
WHERE distance < 51
AND speed = spd.speed)
OR spd.distance = (SELECT MIN (distance)
FROM chtmp
WHERE distance > 51
AND speed = spd.speed)
);

It uses the first sub-query to get the records with the right speed,
then the where clause picks out the desired distances for each speed.

cheers
Chris

.