I'm using Postgres 9.3. given this table:
CREATE TABLE release_country
(
release integer NOT NULL,
country integer NOT NULL,
date_year smallint,
date_month smallint,
date_day smallint,
)
I want a list of the earliest record for each release, in other words there can be multiple records in the table for the same release but different country. I want a list containing the release and the earliest date, but his will not work
select distinct release, min(t1.date_year), min(t1.date_month), min(t1.date_day)
FROM release_country t1
GROUP BY release;
Because it considers each portion of the date seperately. How do I consider the three portions as a single date, also having to contend with only the year portion being mandatory, the month and day portions may be null.