CREATE OR REPLACE VIEW v_current_contact_mechanisms AS
SELECT Prty_ID,
       Come_ID,
       Code,
       Contact_value,
       start_date,
       end_date,
       comments
FROM (SELECT prty.ID AS Prty_ID,
       come_id AS Come_ID,
       come.comt_code AS Code,
       come.contact_value AS Contact_value,
       prty_come.start_date AS start_date,
       prty_come.end_date AS end_date,
       prty_come.comments AS comments,
       MAX(prty_come.start_date) over(PARTITION BY prty.ID, come.comt_code) AS max_start_date
  FROM parties prty,
       party_contact_mechanisms prty_come,
       contact_mechanisms come
 WHERE prty.id = prty_come.prty_id
       AND come.id = prty_come.come_id)
WHERE start_date = max_start_date;
