Question
Please explain what KEEP exactly is and the effect of with/without it.
Looking for an explanation but could not find a clear explanation.
PARTITION BY with and without KEEP in Oracle
The real point/power of "KEEP" is when you aggregate and sort on different columns.
Unfortunately, when you start searching for the "keep" clause, you won't find anything in the Oracle documentation (and hopefully because of this blogpost, people will now have a reference). Of course Oracle documents such functions. You only have to know that they are called FIRST and LAST in the SQL Language Reference.
# However, you can do even better by just adding three "keep clause" functions to the original query:
SELECT
ra.relation_id,
MAX(ra.startdate) startdate,
MAX(ra.address) KEEP(DENSE_RANK LAST ORDER BY ra.startdate) address,
MAX(ra.postal_code) KEEP(DENSE_RANK LAST ORDER BY ra.startdate) postal_code,
MAX(ra.city) KEEP(DENSE_RANK LAST ORDER BY ra.startdate) city
FROM
relation_addresses ra
WHERE
ra.startdate <= to_date(:reference_date, 'yyyy-mm-dd')
GROUP BY
ra.relation_id