Thanks for the reply, but it isn't quite what is needed. The problem is that I need all the records between the two occurances of identical values in field 2, with no records which occur before or after those two occurances. For example, the following table with 3 fields: 1 1 10 2 4 99 3 2 99 4 1 98 5 4 88 6 2 97 If the parameter for the second column is 4, I would need to retrieve records 2, 3, and 4. If the query needs, for simplicity, to return record 5, that could be handled by the program. Thanks for your thoughts!! Charlie > 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 <mysql-unsubscribe-charlie=strategicworldwide [EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php .
--------------------------------------------------------------------- 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