Re: Selecting rows near a particular row
From: Nis Jorgensen <nis_at_dkik.dk>
Date: Thu, 23 May 2002 11:59:21 +0200
Message-ID: <7tepeuk9o6bgkh0m2prsko3fgvh1aojkmk_at_4ax.com>
Date: Thu, 23 May 2002 11:59:21 +0200
Message-ID: <7tepeuk9o6bgkh0m2prsko3fgvh1aojkmk_at_4ax.com>
On 23 May 2002 02:40:55 -0700, rasel.khan_at_corp.vizzavi.net (Rasel Khan) wrote:
>Hi,
>
>I want to list items near a particular item in an indexed database,
>e.g. if the items are ordered into
>
>a,b,c,d,e,f,g,h,i,j ...
>
>and I am looking for 'f'
>
>then I want the rows representing e,f,g or e,g,h if f does not exist,
What is the rule for governing which ones to return? Specifically, why is h returned in the second example, and d not?
>Any help will be appreciated - The thing is I can't do
>select * from table where id >= f-3 limit 5 --- or can I ,
Something like this
SELECT m1.* FROM
myTable AS m1, myTable AS m2
WHERE m2.id BETWEEN 'f' AND m1.ID
OR m2.ID BETWEEN m1.ID AND 'f'
GROUP BY m1.ID
HAVING count(*) <= 2
-- Nis Jorgensen Amsterdam Please include only relevant quotes, and reply below the quoted text. ThanksReceived on Thu May 23 2002 - 11:59:21 CEST