SELECT t.id, t.shipped, c.code companyCode, t.packages, tto.description FROM ticket t JOIN company c ON c.id = t.companyFk LEFT JOIN ticketObservation tto ON tto.ticketFk = t.id AND tto.observationTypeFk = (SELECT id FROM observationType WHERE code = 'deliveryNote') WHERE t.id = ?