That query will give you all release dates for all recordings, not just the earliest ones. You’ll have to sort them. Here’s what the server uses if the recording_first_release_date table is empty:
SELECT DISTINCT ON (track.recording) track.recording,
rd.date_year AS year,
rd.date_month AS month,
rd.date_day AS day
FROM track
JOIN medium ON medium.id = track.medium
LEFT JOIN (
SELECT release, date_year, date_month, date_day FROM release_country
UNION ALL
SELECT release, date_year, date_month, date_day FROM release_unknown_country
) rd ON rd.release = medium.release
WHERE track.recording = ?
ORDER BY track.recording,
rd.date_year NULLS LAST,
rd.date_month NULLS LAST,
rd.date_day NULLS LAST;
Replace WHERE track.recording = ? with whatever condition you’re using.