Yeah, so a UNION would work, would this solution be faster than using
a subquery (my instinct says yes) but thought I would ask. They both
execute fast on my system so it's hard to say under load.
Thanks,
Waynn
On 11/12/08, Dan Nelson [EMAIL PROTECTED] wrote:
In the last episode (Nov 12), Waynn
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 = userId ORDER BY UserId DESC LIMIT 1;
SELECT * FROM Users WHERE UserId = userId ORDER BY UserId LIMIT 1;
Is there any
Whoops, just realized I made a mistake in the examples. What I'm really
looking for is these two queries:
SELECT * FROM Users WHERE UserId *userid*;
SELECT * FROM Users WHERE UserId *userid*;
Waynn
On Wed, Nov 12, 2008 at 12:14 AM, Waynn Lue [EMAIL PROTECTED] wrote:
I'm trying to find the
Select the UserId one less, and then ORDER ASC LIMIT 3.
Assuming your UserId's are sequential, it's easy, given userID X
SELECT * FROM Users WHERE UserId = X-1 ORDER BY UserId ASC LIMIT 3;
If they're not sequential due to deletions, etc, it becomes a bigger
problem. You could do a subquery, but
Micah,
I'm trying to find the first row before and
the first row after a specific row
Here's one way:
drop table if exists t;
create table t(userid int, data int);
insert into t values(1,10),(3,20),(6,30),(8,50),(10,60), (13,80);
-- retrieve rows just before and just after userid=8:
select
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 = userId ORDER BY UserId DESC LIMIT 1;
SELECT * FROM Users WHERE
-Original Message-
From: Waynn Lue [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 12, 2008 3:14 AM
To: MySQL List
Subject: Row before and after?
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