Something
public text v1 · immutableSELECT C.name AS category,
E.name AS port
FROM element E, categories C, ports P
JOIN (SELECT DISTINCT from_port_id as port_id
FROM ports_moved UNION
SELECT DISTINCT to_port_id as port_id
FROM ports_moved ) as tmp on P.id = tmp.port_id
WHERE E.id = P.element_id
AND C.id = P.category_id
ORDER BY 1, 2