How to get the registers in the highest time of period
You are doing a left join that then includes a where clause that is filtering against the b table in the where clause.  I'm guessing you want to say OR b.id IS NULL or something to that affect.
To confirm, comment out the where clause.