简体   繁体   English

即使使用EXISTS也没有结果

[英]No results even by using EXISTS

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) : 我不理解为什么MySQL返回“ MySQL没有产生记录”,而我使用EXISTS(我愿意选择一个不产生记录的子查询):

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. 根据定义,EXISTS允许从不返回任何记录的查询中获取结果。 Until now I've always got NULL in such case. 直到现在,在这种情况下,我总是会得到NULL。

It is returning that message because no records match. 正在返回该消息,因为没有记录匹配。 NULL is a value for a column. NULL是列的值。 It is quite different from an empty return set. 它与空返回集完全不同。

If you have an aggregate function, then the empty set returns a NULL. 如果您具有聚合函数,则空集将返回NULL。 So the following would return a NULL value: 因此,以下代码将返回NULL值:

select max(Page_ID)

and this would return 0: 这将返回0:

select count(Page_ID)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM