0

I have two tables:

Product_Table

ProductID     Name       Date  
1             ABC        2020-02-14  
2             XYZ        2020-03-05

Productbreak_Table

BreakID   Product_id      Begin         End  
34          1             2020-01-01    2020-01-30  
35          1             2020-02-01    2020-02-20  
36          2             2020-01-15    2020-01-31  
37          2             2020-02-15    2020-03-01

My goal is to get just the products whose Date are not between the Begin and End dates of the productbreak_table

Result should be:

ProductID    Name
2            XYZ
Stam
  • 35
  • 5

1 Answers1

1

You would use not exists:

select p.*
from products p
where not exists (select 1
                  from productbreak pb 
                  where pb.productid = p.productid and
                        p.date between pb.begin and pb.end
                 );
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786