SELECT DISTINCT ON (ep.region_id)
  ep.id, ep.region_id, ep.price_mwh, ep.demand_mw, ep.timestamp, ep.source,
  r.code as region_code, r.name as region_name
FROM electricity_prices ep
JOIN grid_regions r ON ep.region_id = r.id
ORDER BY ep.region_id, ep.timestamp DESC
