I have a database with ID's that are non-integers like this:
b01
b02
b03
d01
d02
d03
d04
s01
s02
s03
s04
s05
etc. The letters represent the type of product, the numbers the next one in that group.
I'd like to be able to select an ID, say d01, and get b03, d01, d02 back. How do I do this in MYSQL?
Best Answer
Find your target row,
and the row above it with no other row between the two.
and similarly for the row below it. (Left as an exercise for the reader.)
In my experience this is also quite efficient.