Skip to content

Instantly share code, notes, and snippets.

@jaylevitt
Created April 1, 2012 22:52
Show Gist options
  • Save jaylevitt/2279270 to your computer and use it in GitHub Desktop.
Save jaylevitt/2279270 to your computer and use it in GitHub Desktop.
Posts with position > position of last known ID
CREATE TABLE posts
(
id int primary key,
position int,
animal text
);
INSERT INTO posts
(id, position, animal)
VALUES
(1,1, 'alpaca'),
(2,2, 'bird'),
(3,3, 'cow');
SELECT * from posts
JOIN posts AS last
ON posts.id = last.id
AND last.id = 2
WHERE posts.position > last.position
ORDER BY posts.position;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment