* Mark Lo
> Row 10 ID00010 need this value
> Row 11 ID00025 have this value on hand
> Row 12 ID00063 need this value
>
> The questions is how do I find out the values in Row 10 and Row 12, if and
> only if I only have one data that is "ID00025" (select * from table where
> field="ID00025") . But, the questions is How do I find out the
> data in Row
> 10 and Row 12 which is "ID00010" and "ID00063" assume I don't know the
> values of "ID00025" is in Row 11.
previous: select * from table where field < "ID00025" order by id desc limit
1
next: select * from table where field > "ID00025" order by id limit 1
It is even possible to do this with one select statement and four left joins
to the same table, but it is a bit complicated:
select table.*,next.id as next,prev.id as prev
from table
left join table as prev on
prev.id < table.id
left join table as prev2 on
prev2.id < prev.id
left join table as next on
next.id > table.id
left join table as next2 on
next2.id > next.id
where
table1.id="ID00025" and
not isnull(prev2.id) and
not isnull(next2.id)
--
Roger
query
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php