title: How to get the closest dates in Oracle sql
body: <p>For example, I have 2 time tables:
  T1</p>
  
  <pre><code>id time
  1 18:12:02
  2 18:46:57
  3 17:49:44
  4 12:19:24
  5 11:00:01
  6 17:12:45
  </code></pre>
  
  <p>and T2</p>
  
  <pre><code>id time
  1 18:13:02
  2 17:46:57
  </code></pre>
  
  <p>I need to get time from T1 that are the closest to time from T2. There is no relationship between this tables.
  It should be something like this:</p>
  
  <pre><code>select T1.calldatetime
  from T1, T2 
  where T1.calldatetime between 
  T2.calldatetime-(
      select MIN(ABS(T2.calldatetime-T1.calldatetime))
      from T2, T1)
  and
  T2.calldatetime+(
      select MIN(ABS(T2.calldatetime-T1.calldatetime))
      from T2, T1)
  </code></pre>
  
  <p>But I can't get it. Any suggestions?</p>