Last active
May 3, 2019 08:49
-
-
Save mishadoff/3fe3e600fc37daef4fb70d10e7634ea0 to your computer and use it in GitHub Desktop.
SQL NOT IN EMPTY LIST
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
create table test ( | |
key text, | |
value text | |
); | |
insert into test (key, value) values ('1', 'Pulp Fiction'); | |
insert into test (key, value) values ('2', 'Reservoir Dogs'); | |
insert into test (key, value) values ('3', 'Inglorius Bastards'); | |
insert into test (key, value) values ('4', 'Django'); | |
insert into test (key, value) values ('5', 'Kill Bill'); | |
-- Q1: SELECT ALL / return all items | |
select * from test; | |
-- Q2: SELECT ALL IN / return all items | |
select * from test where key in ('1', '3') | |
union | |
select * from test where key not in ('1', '3'); | |
-- Q3: SELECT ALL IN (null or empty sequence) / return NO items :( | |
select * from test where key in (null) | |
union | |
select * from test where key not in (null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment