From: Dan Nelson Date: November 12 2008 4:12pm Subject: Re: Row before and after? List-Archive: http://lists.mysql.com/mysql/215189 Message-Id: <20081112161218.GK85407@dan.emsphone.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In the last episode (Nov 12), Waynn Lue said: > I'm trying to find the first row before and the first row after a specific > row. Essentially I want to do these two queries, and get each row. > > SELECT * FROM Users WHERE UserId = ORDER BY UserId DESC LIMIT 1; > SELECT * FROM Users WHERE UserId = ORDER BY UserId LIMIT 1; > > Is there any way to combine this into one query? OFFSET doesn't allow a > negative number, which is essentially what I want. How about joining them with a UNION? Two queries for the round-trip cost of one! -- Dan Nelson dnelson@stripped