I am frontend engineer building something with supabase, I have written this postgres function
DROP FUNCTION IF EXISTS get_schedule_checklist_data;
CREATE OR REPLACE FUNCTION get_schedule_checklist_data(
schedule_id UUID,
blueprint_id_value UUID,
event_type service_configuration_type
)
RETURNS TABLE (
title TEXT,
schedule_id UUID,
checklist_id UUID,
completed BOOLEAN,
performed_by TEXT,
performed_on_date TIMESTAMPTZ,
parent_id uuid,
order_number INT8,
event_type TEXT,
archived BOOLEAN
)
LANGUAGE sql
AS $function$
SELECT
bc.title,
bcm.schedule_id, -- This could be null
bc.id AS checklist_id,
bcm.completed,
bcm.performed_by,
bcm.performed_on_date,
bc.parent_id,
bc.order as order_number,
bc.event_type,
bc.archived
FROM
blueprint_checklist bc
LEFT JOIN
blueprint_schedule_completion_mapping bcm
ON
bcm.schedule_id = schedule_id AND bc.id = bcm.blueprint_checklist_id
WHERE
bc.blueprint_id = blueprint_id_value
AND bc.event_type = event_type;
$function$;
in this, for bcm.schedule_id = schedule_id AND bc.id = bcm.blueprint_checklist_id
condition, I only want the record with most recent performed_on_date
in table.
How can I do it?