I'm almost sure i am doing something wrong, but i cannot figure out what exactly.

The query runs fine a few times, and sometimes returns an empty `aff_affiliatelink`, for no reason.
If i remove the RAND() from the first JOIN, everything works fine, but, i need a random affiliate...
any idea on what might be causing this ?

**EDIT**: Just noticed something, the game\_software for the failed `aff_affiliatelink` is always "2". Don't know if it has any connection, but it might be useful in understanding what is wrong.

Here is my query:

```
   SELECT game_software,
          aff_affiliatelink
     FROM games g     
LEFT JOIN (SELECT asoft_affiliateid,asoft_softwareid 
             FROM affiliates_software 
         ORDER BY RAND() ) aff_soft ON aff_soft.asoft_softwareid =g.game_software    
LEFT JOIN (SELECT aff_id, 
                  aff_affiliatelink,
                  aff_description,
                  aff_bonus,
                  aff_title,
                  aff_image,
                  aff_imagealt,
                  aff_banner,
                  aff_banneralt 
             FROM affiliates 
            WHERE aff_isactive = 1) aff ON aff_id=aff_soft.asoft_affiliateid     
 GROUP BY game_id 
 ORDER BY game_releasedate DESC

```

**EDIT** : After changing the second LEFT JOIN to INNER JOIN,
It seems to work, but im not sure that is the correct way of doing it....
if anyone has another idea, please tell, i will leave this question open until i will get a decent answer.