Reputation: 548
I like to keep all records in tableA that are right after my targeted date,
Main table A
Table B
SELECT *
FROM tableA a
LEFT JOIN tableB b on b.customerID = a.customerID and b.target_date = a.sell_date
WHERE a.sell_date > b.target_date
Unfortunately my code above doesn't work since SQL can't compare NULL with date.
My expected output is
Upvotes: 0
Views: 32
Reputation: 6015
The inequality between target_date and sell_date could go in the join condition of the FROM clause. This way the WHERE clause could be eliminated.
SELECT *
FROM tableA a
LEFT JOIN tableB b on b.customerID=a.customerID
and b.target_date <= a.sell_date;
Upvotes: 1