I have this table of contracts where I have parent contracts and sub contracts. I want to select all the parent contracts with the number of their subordinate contracts.
SELECT
sup.id_contract, sup.parent_id, sup.contractor_name
IFNULL(count(sub.id_contract),0) AS orders
FROM Contracts sub
LEFT JOIN Contracts sup ON sub.parent_id=sup.id_contract
where sup.deleted !=1 GROUP BY sup.id_contract;
but for me, parent contract it also a contract with parent_id=NULL and its "orders" can be '0'
How can i do that to select also all Contracts with parent_id NULL where amount of orders will be 0?