Assuming at least one ticket, you could do this instead:
SELECT MAX(g.ticket) FROM ticket_custom g WHERE g.ticket=id
You can convert that to a JOIN or nested SELECT etc.
so change id=c.ticket id=MAX(c.ticket)
but check your WHERE & LEFT JOIN there's some strange stuff in there.