sql - COUNT ifnull mysql query -


i have 2 tables in database, fleets , personnel_onboard_fleets. trying list of of fleets (which works) , count how many personnel onboard each fleet (which doesn't). however, isn't showing results if there aren't personnel onboard.

select f.*, count(pof.id) onboard  fleets f, personnel_onboard_fleets pof  f.fleet_id = pof.fleet_id order f.status 

i expecting 2 results, 1 fleet 2 people on board , 1 0 people onboard. 1 result. have tried use following

select f.*,  ifnull(count(pof.id), 0) onboard  fleets f, personnel_onboard_fleets pof  f.fleet_id = pof.fleet_id order f.status 

i cant see wrong query, there else needs added show fleets 0 persons onboard.

my original query before count shows fleets fine, know count.

this driving me crazy! appreciated!!

try:

select f.fleet_id,        count(pof.id) onboard   fleets f        left join personnel_onboard_fleets pof               on f.fleet_id = pof.fleet_id group  f.fleet_id order  f.status;   

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -