I have 2 tables client and followup. I need to select based on following conditions.
If subscriber_id in table client t1 NOT IN followup table t2 and t1.paid_amount = 0 AND t1.update_balance > 200
OR
If subscriber_id IS IN table followup t2 and and t1.paid_amount = 0 AND t1.update_balance > 200 AND ALSO if t1.update_time GREATER THAN t2.update_time. Both the update_time in both tables are in MYSQL TIMESTAMP Format.
My current query is as follows:
SELECT t1.id,t1.subscriber_id,t1.paid_amount,t1.update_balance
FROM client AS t1
LEFT OUTER JOIN followup AS t2 ON t1.subscriber_id = t2.subscriber_id
WHERE (t2.subscriber_id IS NULL AND t1.paid_amount = 0 AND t1.update_balance > 200) OR (t2.subscriber_id IS NOT NULL AND t1.paid_amount = 0 AND t1.update_balance > 200 AND 't1.update_time'> 't2.update_time')
But the data is not selected if t1.update_time > THAN t2.update_time..
Client Table:
-------------------------------------------------------------------
id subscriber_id paid_amount update_balance update_time
--------------------------------------------------------------------
1 AB4567 0 500 2020-07-12 18:22:24
2. AB4568 0 300 2020-07-15 17:22:24
--------------------------------------------------------------------
Followup Table
------------------------------------------------------------------
id subscriber_id feedback update_time
-------------------------------------------------------------------
1. AB4567 paid 2020-07-12 17:22:24
-------------------------------------------------------------------
- If subscriber_id NOT IN table 2 - Display ROW
- If subscriber_id IN table 2 - Display if t1.update_time > t2.update_time
Requesting Help from Mysql Experts..