Calling all SQL Geeks! I have a strange SELECT statement need. I have a table, the rows of which may be sorted in any number of ways. Regardless of the way it's sorted, I want to find the row where, say, event.date = "2008-07-05", and find the next and previous rows. The dates will not be contiguous; they may be seperated by weeks or even months, nor will the request necessarily be sorted by date.
Right now I'm creating a prev/cur/next queue and iterating through the result rows until I hit the entry I'm looking for, then iterating one more time to get the "next" entry. That hardly seems satisfactory. It seems natural to me that SQL would have something like this.
I've looked at the SELECT documentation from MySQL and there doesn't seem to be much there that would help me.
Right now I'm creating a prev/cur/next queue and iterating through the result rows until I hit the entry I'm looking for, then iterating one more time to get the "next" entry. That hardly seems satisfactory. It seems natural to me that SQL would have something like this.
I've looked at the SELECT documentation from MySQL and there doesn't seem to be much there that would help me.
no subject
Date: 2008-07-26 03:59 am (UTC)ORDER BYbits. But I guess I didn't quite grasp the exact nature of the problem - if he's doing what it sounds like he's doing (grabbing the previous/next story in a thread?) then there's probably a cleaner way of doing it by restructuring the data. Would depend on what the exact purpose of the task is and what the restrictions on it are, though - if threads always run "forwards in time", then a variant on my original query would work; if they aren't guaranteed to go in the same direction, though, then something messier might be necessary.