title: SQL : Comparing multiple values in one table with a single value in another Table
body: <p>I have two tables Table 1 and Table 2</p>
  
  <p><strong>Table 1:</strong></p>
  
  <pre><code>-------------------------------
  | Ser | StartDate  | Activity |  
  -------------------------------
  |  1  | 2002-10-13 |    1     |  
  |  1  | 2002-10-13 |    2     |  
  |  1  | 2007-09-04 |    3     |  
  </code></pre>
  
  <p><strong>Table 2:</strong></p>
  
  <pre><code>------------------------
  |Ser|DateOfRegistration|  
  ------------------------
  | 1 |  2002-10-12      |  
  | 1 |  2007-09-02      |
  </code></pre>
  
  <p>Now, the result that I want is such that for Activity 1 and 2 the Date of registration should be before the Start Date and difference between the dates must be the least. Similarly, for Activity 3, the date of registration for Activity 3 should be before the start date. The result should look like this.</p>
  
  <p><strong>Table 3:</strong>  </p>
  
  <pre><code>--------------------------------------------
  |Ser|StartDate |DateofRegistration|Activity|  
  --------------------------------------------
  | 1 |2002-10-13|  2002-10-12      |   1    |  
  | 1 |2002-10-13|  2002-10-12      |   2    |  
  | 1 |2002-09-04|  2002-09-02      |   3    |  
  </code></pre>
  
  <p>How can I join Table 1 and 2 to get Table 3?</p>