Yeah, sorry about that. In two statements:

select max(number) from table where number < ?
select min(number) from table where number > ?

if you want to merge them into a single statement, you can do:
select (select max(number) from table where number < ?)
highest_smaller, (select min(number) from table where number > ?)
lowest_greater;

On Mon, Jul 13, 2009 at 7:32 PM, Bogdan Nicula<bogda...@hotmail.com> wrote:
>
>
> Thank you for your answer.
> Looking back to my original email, I believe I didn't explain well enough: I 
> want to find the highest smaller and lowest greater numbers enclosing the 
> number.
> For example, given the sequence: 1, 3, 5, 7, 9, etc., if I query for 6, I 
> would like to get 5 and 7.
>
> Thanks,Bogdan
>
>>
>> Select max(number), min(number) from table;
>>
>> Wes
>>
>> On Mon, Jul 13, 2009 at 7:16 PM, Bogdan Nicula wrote:
>>>
>>>
>>> Hi,
>>>
>>> Sorry for my lack of SQL knowledge which triggered this help request:
>>> Given a column containing numbers, which is the most efficient manner to 
>>> find out the highest smaller and lowest greater number?
>>> That is, is there a better way than:
>>>
>>> select * from table where number <= ? order by number desc limit 1;
>>> select * from table where number>= ? order by number asc limit 1;
>>>
>>>
>>> What if the table contains millions of rows?
>>>
>>> Thank you for any help,Bogdan
>>> _________________________________________________________________
>>
>
> _________________________________________________________________
> Share your memories online with anyone you want.
> http://www.microsoft.com/middleeast/windows/windowslive/products/photos-share.aspx?tab=1
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to