SELECT p.*, p.id AS portfolio_id, YEAR( p.contract_datum ) AS year FROM edn_portfolio p INNER JOIN edn_portfolio_lijst pl ON pl.id = p.lijst_id AND pl.status = 0 WHERE p.nr = '1870' GROUP BY p.nr ORDER BY pl.volgnr DESC , contract_datum DESC