I have two tables:
- 1 with an Unique ID with the first time they visited (in date format)
- and a historical addresses table with the same Unique ID, a start field (date field), an end field (date field) and the addresses fields.
What I like to do is create a table which get the addresses of the persons (Unique ID) based on the date where they lived at the time of the visit.
I'm able to select records with my own made up dates, but I would like to get them from the 'first time visit' field.
The SQL query with random dates:
SELECT * FROM historical_adresses
WHERE (startdate, enddate) OVERLAPS ('2013-05-15'::DATE, '2013-05-15'::DATE);
Who can help me do this in PostgresSQL?