I have the following query that produces multiple records for a single id. I'm trying to figure out how to merge these multiple records into one record:
SELECT DISTINCT id, gender, dateofbirth, city, state, zip
FROM t
This may give me the following resultset:
1, M, 2000-01-01, dallas, tx, 12345
1, M, 2000-01-01, NULL, NULL, NULL
What I want is a single record:
1, M, 2000-01-01, dallas, tx, 12345
A similar scenario occurs when the second row has different data:
1, M, 2000-01-01, dallas, tx, 12345
1, M, 2000-01-01, houston, tx, 67890
In this case I would just want to pick one of the records and ignore the other in order to only have a single record per id.
Is there a way to do this in PostgreSQL? I've tried coalesce to no avail and is wondering if there is some way to handle this.