SELECT useridfrom, count(*) as count FROM mdl_message WHERE useridto = 896 AND timeusertodeleted = 0 AND notification = 0 GROUP BY useridfrom Empty set (0.00 sec) +----+-------------+-------------+------+-----------------------------------------------------------------------+------------------------+---------+-------------------+------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------------+------+-----------------------------------------------------------------------+------------------------+---------+-------------------+------+----------------------------------------------+ | 1 | SIMPLE | mdl_message | ref | mdl_mess_useusetimtim_ix,mdl_mess_usetimnot_ix,mdl_mess_usetimnot2_ix | mdl_mess_usetimnot2_ix | 18 | const,const,const | 1 | Using where; Using temporary; Using filesort | +----+-------------+-------------+------+-----------------------------------------------------------------------+------------------------+---------+-------------------+------+----------------------------------------------+ 1 row in set (0.00 sec)