I can not find where is the problem, my COUNT() returns the same number for both values contracts_count and records_count. When using only one of counts, everything works fine. Principle of this query: access company table, get it's id and name, company and group is related with foreign key in contract table, and record has foreign key related to group table. So I join company with contracts to get contracts count of each company and join group with contracts, records with group to get records count of each company.
SELECT
`company`.`id`,
`company`.`name`,
COUNT(`contract`.`contract_id`) AS contracts_count,
COUNT(`record`.`record_id`) AS records_count
FROM `company`
LEFT JOIN `contract`
ON `company`.`id`=`contract`.`fk_companystudijos_id`
LEFT JOIN `group`
ON `contract`.`fk_groupID`=`group`.`id`
LEFT JOIN `record`
ON `group`.`id`=`record`.`fk_groupID`
GROUP BY `company`.`id`
ORDER BY contracts_count DESC