Created
October 3, 2012 21:55
-
-
Save infogulch/3830136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table t1 contains 4 rows, with id = 1, 2, 3, 5 | |
SELECT X, Y | |
FROM ( | |
SELECT A.id as X, (SELECT MIN(b.id) FROM t1 AS B WHERE B.id > A.id) as Y | |
FROM t1 AS B | |
) C | |
WHERE Y IS NOT NULL | |
id1 | id2 | |
-----+------ | |
1 | 2 | |
2 | 3 | |
3 | 5 | |
(4 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment