I'm banging my head against the wall.. I have 2 tables, orders and batches. I'm using PostgreSQL 9.
These queries work and return results as I'd expect:
Query #1 (works appropriately, returning order #12, #8, etc.):
SELECT "orders".* 
FROM "orders" 
    INNER JOIN "batches" ON "batches"."order_id" = "orders"."id" 
WHERE (order_id not IN (14,4,13,5,2,9,3,7,11));
Query #2 (works appropriately, returning unique order IDs that have batches with an estimated end date later than 2019-08-06 - the same as the numbers listed above):
SELECT DISTINCT "batches"."order_id" 
FROM "batches" 
WHERE (estimated_end_date >= '2019-08-06');
However, if I put select query #2 in place of the number list, it doesn't return the same results as query #1 as I'd expect:
SELECT "orders".* 
FROM "orders" 
    INNER JOIN "batches" ON "batches"."order_id" = "orders"."id" 
WHERE (order_id not IN (SELECT DISTINCT "batches"."order_id"          
                                FROM "batches" 
                                WHERE (estimated_end_date >= '2019-08-06')))
What am I doing wrong? How do I get the nested subquery to work properly? THANK YOU!
 
     
     
     
    