On 11/12/02 12:43 PM, "Charlie" <[EMAIL PROTECTED]> wrote: > I can't seem to come up with a solution to the following SQL query, and have > a project dependent on a solution. I'd rather not load the whole database > and then parse it in the code. > > With the following Database structure: > Field0 Integer Autonumber > Field1 Integer Unique > Field2 Integer not unique > > where the starting record would be selected by Field1 (an indexed field of > unique values). > > The ending record required would be the first succeeding record where the > value of Field2 is equal to the value of Field2 in the 'starting' record. > > Field2 is NOT unique and not ordered. > The result would be ordered by Field0 (the autonumber field) > > Is this possible?
I am not sure if I understood your mail correctly but you can try this: If you've not already done it, create an UNIQUE index for field1 and an INDEX for field2 and then try the query with a self-join on your table. SELECT foo1.* FROM yourtable foo1, yourtable foo2 WHERE foo1.field0 = foo2.field0 AND foo1.field2 = foo2.field2 AND foo1.field1 = your_starting_value ORDER BY foo1.field0 ASC /h --------------------------------------------------------------------- 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