Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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