SELECT COUNT(echostar.UPGRADES.campaign) AS Count_of_Campaign, echostar.UPGRADES.campaign, ecreek.agent_hr.position_title FROM ecreek.agent_hr INNER JOIN echostar.UPGRADES ON ecreek.agent_hr.AgentId = echostar.UPGRADES.seller WHERE ecreek.agent_hr.position_title = '$team' AND echostar.UPGRADES.`timestamp` BETWEEN '$date2' AND '$date1' GROUP BY echostar.UPGRADES.campaign\ +----+-------------+----------+------+----------------+----------------+---------+-------+------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------+------+----------------+----------------+---------+-------+------+----------------------------------------------+ | 1 | SIMPLE | UPGRADES | ref | timestamp | timestamp | 3 | const | 10 | Using where; Using temporary; Using filesort | | 1 | SIMPLE | agent_hr | ref | position_title | position_title | 7 | const | 89 | Using where | +----+-------------+----------+------+----------------+----------------+---------+-------+------+----------------------------------------------+ 2 rows in set, 7 warnings (0.00 sec)