The statement looks nice and valid Rudy! But weird..its still retrieving content later than lastUpdate, plus the status column is showing "2" for those content earlier than lastUpdate while the content which shouldn't be showing becomes "1". Also the lastUpdate date becomes null. Any idea?
Code:
Result:
+-------------+-----------+------------------------+-----------+------------------------+
| contentID | content | created | status | lastUpdate |
+-------------+-----------+------------------------+-----------+------------------------+
| 1 | testing | 2012-06-19 20:21:00 | 2 | 2012-06-19 20:21:16 |
+-------------+-----------+------------------------+-----------+------------------------+
| 1 | testing1 | 2012-06-19 20:21:16 | 2 | 2012-06-19 20:21:16 |
+-------------+-----------+------------------------+-----------+------------------------+
| 1 | testing2 | 2012-06-19 20:21:30 | 1 | NULL |
+-------------+-----------+------------------------+-----------+------------------------+
SELECT mc.contentID, mc.content, mc.created, ms.status, ms.lastUpdate
FROM message_status AS ms
INNER
JOIN message_content AS mc
ON mc.contentID = ms.contentID
AND mc.created <=
CASE WHEN ms.status = 2
THEN ms.lastUpdate
ELSE mc.created END
Bookmarks