Skip to content

Instantly share code, notes, and snippets.

@avbelyaev
Last active September 29, 2021 20:44
Show Gist options
  • Save avbelyaev/d86f6a34cadc339ef4dfbb2d2080d156 to your computer and use it in GitHub Desktop.
Save avbelyaev/d86f6a34cadc339ef4dfbb2d2080d156 to your computer and use it in GitHub Desktop.
TP
-- create table tmp2(
-- foo int
-- )
-- insert into tmp values (1),(2),(4),(4),(5),(null);
-- insert into tmp2 values (1),(3),(4),(4),(5),(5),(null);
-- select tmp.foo, tmp2.foo
-- from tmp
-- inner join tmp2 on tmp.foo = tmp2.foo
-- create table emp(
-- id int,
-- chef_id int,
-- dept int
-- );
-- insert into emp values
-- (1,null,1),
-- (2,1,1),
-- (3,1,2),
-- (4,2,3),
-- (5,3,1),
-- (6,1,2);
-- select *
-- from emp a
-- left join emp b on b.id = a.chef_id and b.dept = a.dept
-- where b.id is null
-- select *
-- from emp a
-- left join emp b on b.id = a.chef_id
-- where b.id is not null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment