Joining time fields?

From: James David Smith <james(dot)david(dot)smith(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Joining time fields?
Date: 2012-07-24 14:57:48
Message-ID: CAMu32ABbSUgpQeGha+ZZDfvjMuU=9kPAxzsWxXwZipZgdp34nw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi all,

I wonder if someone could help me out please. I've got two tables, both
with a TIMESTAMP field. I'd like to do a left join with them. I'd like to
take the date_time from table A, and join it with the nearest date_time
from table B. Whether the time from B is before or after the time in A
doesn't matter, I just want the closest time. I started with the below
query, but it only gets me the column from table B if the time stamp
exactly matches which is clearly correct. I'm sure that this should be
quite easy but I can't figure it out...!

Select

a.date_time

b.date_time

FROM table_one a

LEFT JOIN table_two b ON a.date_time = b.date_time

Thanks

James

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Oliveiros d'Azevedo Cristina 2012-07-24 15:25:19 Re: Joining time fields?
Previous Message Jan Niederhumer 2012-07-24 09:32:12 pg_upgradecluster hook-scripts