SELECT
d.id,
d.created
FROM ticket t
JOIN ticketDms dt ON dt.ticketFk = t.id
JOIN dms d ON d.id = dt.dmsFk
AND d.file LIKE '%.png'
WHERE t.id = ?