Join tables by nearest date?

From: Nick <nboutelier(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Join tables by nearest date?
Date: 2009-07-28 05:51:00
Message-ID: 5d54345d-3a9b-43bf-b23f-effca9345624@q40g2000prh.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is it possible to join two tables by the nearest date? For example how
could I find out where the user was on their birthday?

users (id, name, birthday)
1 | one | 2009-07-27
2 | two | 2009-07-28
3 | three | 2009-07-29
4 | four | 2009-07-30
5 | five | 2009-07-31

users_locations (id, user_id, created)
1 | 1 | 2009-05-21
2 | 1 | 2009-06-21
3 | 1 | 2009-07-21
4 | 2 | 2009-05-10
5 | 2 | 2009-06-10
6 | 2 | 2009-07-10

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GÜNDÜZ 2009-07-28 06:07:21 Re: Building from source vs RPMs
Previous Message Brendan Hill 2009-07-28 04:23:43 Idle processes chewing up CPU?