Re: sql select question



hilz wrote:
Hi all
this is more of an SQL question than a Java question.
I have a table with a SPEED column and some other columns like this:

SPEED SOME_OTHER_COLUMNS....
----- ------------------
100 some values here...
34
97
68
13
27
44


now I want to select the two rows that surround a value I am interested
in. For example, if I am interested in a value of 55, I want to select
the two rows that have a speed of 44 and 68.
Is there a way of doing that in SQL ?
i can handle the case where i get an exact match separately.
I just need to know how to select exactly two rows (the one above the
given value and the one below it).


Thanks for any help.

select *
from aTable
where speed = (select max(speed) from aTable where speed < 55)
or speed = (select min(speed) from aTable where speed > 55)

.



Relevant Pages

  • sql select question
    ... this is more of an SQL question than a Java question. ... I have a table with a SPEED column and some other columns like this: ... now I want to select the two rows that surround a value I am interested in. ...
    (comp.lang.java.databases)
  • Re: sql select question
    ... this is more of an SQL question than a Java question. ... I have a table with a SPEED column and some other columns like this: ... Is there a way of doing that in SQL? ...
    (comp.lang.java.databases)