By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table my_table (name varchar(20), date date);
insert into my_table (name, date) values
('John', '2019-04-01'),
('Ally', '2019-04-01'),
('Steve', NULL),
('James', '2019-04-15'),
('James', NULL);
5 rows affected
select name
from my_table t
where
date = '2019-04-15'
and exists (
select 1 from my_table
where name = t.name and date is null
)
name |
---|
James |
select t.*
from my_table t
where (
date = '2019-04-15'
and exists (
select 1 from my_table
where name = t.name and date is null
)
) or (
date is null
and exists (
select 1 from my_table
where name = t.name and date = '2019-04-15'
)
)
name | date |
---|---|
James | 2019-04-15 |
James | null |