I have two tables where I would like to query the most recent status event from including a couple of additional data from both tables. The query below will give all statuses (ll.internal_status) but I would like to only query the most recent one for one boxid. Very much appreciate help on how to best solve it.
SELECT
pdl.delivery_date,
pdl.boxid,
pdl.customer_id,
ll.internal_status,
ll.status_detail,
`datetime`
FROM uploads.opsbi_de_pdl_sequence_trackingdata_at_de as pdl
LEFT JOIN lassy_live_tables.shipping_label_tracker_updated as ll
ON if(istrue(pdl.hf_week > '2021-W15'),pdl.parent_boxid,pdl.boxid) = ll.box_id
WHERE pdl.carrier = 'feibra'
AND pdl.hf_week = '2022-W17'