Skip to content

Instantly share code, notes, and snippets.

@jship
Created December 16, 2022 15:08
Show Gist options
  • Save jship/0c1af274d7cc46a643fb4e2f439e6679 to your computer and use it in GitHub Desktop.
Save jship/0c1af274d7cc46a643fb4e2f439e6679 to your computer and use it in GitHub Desktop.
Simple examples of left vs inner join lateral in PostgreSQL
-- 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