Created
December 16, 2022 15:08
-
-
Save jship/0c1af274d7cc46a643fb4e2f439e6679 to your computer and use it in GitHub Desktop.
Simple examples of left vs inner join lateral in PostgreSQL
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
-- i | i | |
-- ---+--- | |
-- 1 | | |
-- 2 | 2 | |
-- (2 rows) | |
select * | |
from ( | |
values (1), (2) | |
) x(i) | |
left join lateral ( | |
select * | |
from ( | |
values (2), (3) | |
) y(i) | |
where x.i = y.i | |
) y(i) on true | |
; | |
-- i | i | |
-- ---+--- | |
-- 2 | 2 | |
-- (1 row) | |
select * | |
from ( | |
values (1), (2) | |
) x(i) | |
inner join lateral ( | |
select * | |
from ( | |
values (2), (3) | |
) y(i) | |
where x.i = y.i | |
) y(i) on true | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment