Ignore a WHERE clause if nested query returns nothing?
How do I ignore the second WHERE clause if my inner join doesn't return anything?
SELECT MAX( DATE ) , URL
FROM History
WHERE UID = '$uid'
AND DATE < ( SELECT MAX( DATE ) FROM History WHERE URL = '$url' AND UID = '$uid' )
GROUP BY URL
ORDER BY DATE DESC
L开发者_运维知识库IMIT 1
Basically if my inner join doesn't return anything the query should be:
SELECT MAX( DATE ) , URL
FROM History
WHERE UID = '$uid'
GROUP BY URL
ORDER BY DATE DESC
LIMIT 1
精彩评论