A MySQL query needs the results of a subquery in different places, like this:

    SELECT COUNT(*),(SELECT hash FROM sets WHERE ID=1) 
         FROM sets 
         WHERE hash=(SELECT hash FROM sets WHERE ID=1) 
               and XD=2;

Is there a way to avoid the double execution of the subquery `(SELECT hash FROM sets WHERE ID=1)`?
The result of the subquery always returns an valid hash value.
It is important that the result of the main query also includes the HASH. 

First I tried a `JOIN` like this:

    SELECT COUNT(*), m.hash FROM sets s INNER JOIN sets AS m
         WHERE s.hash=m.hash AND id=1 AND xd=2;

If XD=2 doesn't match a row, the result is:

    +----------+------+
    | count(*) | HASH |
    +----------+------+
    |        0 | NULL | 
    +----------+------+

Instead of something like (what I need):

    +----------+------+
    | count(*) | HASH |
    +----------+------+
    |        0 | 8115e| 
    +----------+------+

Any ideas? Please let me know! Thank you in advance for any help.