Reputation: 15080
I have the following table:
-----------------------------
| id | deadline | Notify |
-----------------------------
| 1 | 2017-06-16 | 4 | // true
| 2 | 2017-06-17 | 5 | // true
| 3 | 2017-06-18 | 5 | // false -> tomorrow
| 4 | 2017-06-19 | 6 | // false -> tomorrow
-----------------------------
The notify column present the days before the deadline when a notification should be sent.
Using the following query gives me the record for all the deadlines in 5 days
SELECT * FROM `issues` WHERE deadline = DATE(NOW() + INTERVAL 5 DAY)
How can I use the cell information of the same row? So that, in this example, I get the rows #1 and #2?
Upvotes: 1
Views: 79
Reputation: 49
The deadline - current date gives the number of days before expiring. So try
SELECT * FROM `issues` WHERE DATE(deadline) - DATE(NOW()) <= 5
Upvotes: 0
Reputation: 72185
Try this:
SELECT *
FROM issues
WHERE deadline - INTERVAL Notify DAY <= NOW()
The above query returns rows 1, 2
. If you want to return all rows with a true, false
flag then you can try the following query:
SELECT *,
IF(deadline - INTERVAL Notify DAY <= NOW(), true, false) AS flag
FROM issues
Upvotes: 2