fixed query for CRM-13147

fixed query for CRM-13147