title: MySQL select DATETIME similar up to the minute
body: <p>I have to comapre the results relative to the same time between two tables, but the time stamps differs of some second because of how they were recorded.
  I would like to obtain a result like in <strong>Example 1</strong> but I get only the values with the asterisk, as in <strong>Example 2</strong>.
  What is the best way to remove the secods from the comparison, or to select the value corresponding to the closest DATETIME value?</p>
  
  <p>Currently I'm using this query:</p>
  
  <pre><code>SELECT Table1.TimeSTamp1, Table1.Param1, Table2.TimeStamp2, Table2.Param2 
      FROM Table1, Table2 
      WHERE ... conditions for the other parameters of Table1 and Table2... 
      AND Table1.TimeSTamp1 = Table2.TimeStamp2
  </code></pre>
  
  <p>Any suggestion on the best practice is warmly welcomed.</p>
  
  <hr>
  
  <p><strong>Example 1</strong></p>
  
  <pre><code>TimeStamp1          ¦   Param1  ¦   TimeStamp2          ¦   Param2
  2011-01-01 00:00:35 ¦   1       ¦   2011-01-01 00:00:35 ¦   a       *
  2011-01-01 00:01:35 ¦   2       ¦   2011-01-01 00:01:35 ¦   b
  2011-01-01 00:02:37 ¦   3       ¦   2011-01-01 00:02:35 ¦   c
  2011-01-01 00:03:31 ¦   4       ¦   2011-01-01 00:03:35 ¦   d
  2011-01-01 00:04:32 ¦   5       ¦   2011-01-01 00:04:35 ¦   e
  2011-01-01 00:05:38 ¦   6       ¦   2011-01-01 00:05:35 ¦   f
  2011-01-01 00:06:36 ¦   7       ¦   2011-01-01 00:06:36 ¦   g       *
  2011-01-01 00:07:32 ¦   8       ¦   2011-01-01 00:07:35 ¦   h
  2011-01-01 00:08:33 ¦   9       ¦   2011-01-01 00:08:35 ¦   i
  2011-01-01 00:09:33 ¦   10      ¦   2011-01-01 00:09:33 ¦   l       *
  2011-01-01 00:10:35 ¦   11      ¦   2011-01-01 00:10:35 ¦   m       *
  2011-01-01 00:11:29 ¦   12      ¦   2011-01-01 00:11:31 ¦   n
  </code></pre>
  
  <p>lll
  <strong>Example 2</strong></p>
  
  <pre><code>TimeStamp1          ¦   Param1  ¦   TimeStamp2          ¦   Param2
  2011-01-01 00:00:35 ¦   1       ¦   2011-01-01 00:00:35 ¦   a
  2011-01-01 00:06:36 ¦   7       ¦   2011-01-01 00:06:36 ¦   g
  2011-01-01 00:09:33 ¦   10      ¦   2011-01-01 00:09:33 ¦   l
  2011-01-01 00:10:35 ¦   11      ¦   2011-01-01 00:10:35 ¦   m
  </code></pre>