SELECT IF(incotermsFk IS NULL, FALSE, TRUE) AS hasIncoterms
    FROM ticket t
        JOIN invoiceOut io ON io.ref = t.refFk
        JOIN client c ON c.id = t.clientFk  
        JOIN address a ON a.id = t.addressFk  
    WHERE io.id = ? 
        AND IF(c.hasToinvoiceByAddress = FALSE, c.defaultAddressFk, TRUE)  
    LIMIT 1