I have 2 tables in my database, fleets and personnel_onboard_fleets. I am trying to get a list of all of the fleets (which works) and count how many personnel are onboard each fleet (which doesn't). However, it isn't showing up the results if there aren't any personnel onboard.
SELECT f.*, count(pof.ID) AS onboard
FROM fleets f, personnel_onboard_fleets pof
WHERE f.fleet_ID = pof.fleet_ID ORDER BY f.status
I am expecting 2 results, one fleet with 2 people on board and one with zero people onboard. However I only get the one result. I have tried to use the following
SELECT f.*, IFNULL(COUNT(pof.ID), 0) AS onboard
FROM fleets f, personnel_onboard_fleets pof
WHERE f.fleet_ID = pof.fleet_ID ORDER BY f.status
I cant really see what is wrong with the query, is there anything else that needs to be added to show fleets with 0 persons onboard.
My original query before the count shows all fleets fine, so I know it is something to do with the count.
This is driving me crazy! Any help would be much appreciated!!