I have two tables: contracts
and contract_descriptions
.
On contract_descriptions
there is a column named contract_id
which is equal on contracts
table records.
I am trying to join the latest record on contract_descriptions
:
SELECT *
FROM contracts c
LEFT JOIN contract_descriptions d ON d.contract_id = c.contract_id
AND d.date_description =
(SELECT MAX(date_description)
FROM contract_descriptions t
WHERE t.contract_id = c.contract_id)
It works, but is it the performant way to do it? Is there a way to avoid the second SELECT
?