Three tables, columns:
A: A_id, B_id, C_id, flag, ... B: B_id, date, ... C: C_id, date
If A.flag is NULL, I need all the lines from A connected to B by B_id that B.date had in the past.
If A.flag is not NULL, then I need all the lines from A connected to B on B_id that have Cdate in the past, C joins on C_id.
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 line A.flag is NULL
to stop it connecting to every line from C. This is something that I cannot solve.
Or is there an easier way to do this?
source share