elfs: (Default)
[personal profile] elfs
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.

Date: 2008-07-26 03:59 am (UTC)
From: [identity profile] duskwuff.livejournal.com
Yeah, I forgot the ORDER BY bits. 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.

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 9th, 2026 06:54 am
Powered by Dreamwidth Studios