I don’t undersand why MySQL returns “MySQL did not produce a record” whereas I use EXISTS (I willingly chose a subquery which doesn’t produce records) :
SELECT page_ID
FROM ranks_update
WHERE EXISTS (
SELECT *
FROM ranks_update
WHERE ranking_ID = 3
AND current_rank = 1
AND rating_time < '2012-08-05 02:57:59'
AND rating_time >= '2012-08-05 00:00:00'
GROUP BY page_ID
);
By definition EXISTS allows to get a result from a query which doesn’t return any records. Until now I’ve always got NULL in such case.
It is returning that message because no records match. NULL is a value for a column. It is quite different from an empty return set.
If you have an aggregate function, then the empty set returns a NULL. So the following would return a NULL value:
and this would return 0: