Three tables, columns as follows:
A: A_id, B_id, C_id, flag, ...
B: B_id, date, ...
C: C_id, date
If A.flag is NULL, then I need all rows from A joined with B on B_id that have B.date in the past.
If A.flag is not NULL, then I need all rows from A joined with B on B_id that have C.date in the past, C being joined on C_id.
An attempt:
SELECT *
FROM A, B, C
WHERE A.A_id = B.B_id
AND ((A.flag IS NULL AND (NOW() > B.date) OR
(A.flag IS NOT NULL AND (NOW() > C.date) AND C.C_id = A.C_id))
But I need some condition in the A.flag is NULLline to stop it joining with each row from C. That is what I can’t work out.
Or is there an easier way to do this?
You could try