title: How to retrieve Closest date from another table dynamically MySQL
body: <p>I have two tables:</p>
  
  <p><strong><code>INFO</code> table</strong></p>
  
  <pre><code>ID        LockDate            Investor 
  157       10/15/2018          TEST1
  VF1       09/02/2018          TEST2
  LO2       05/01/2018          TEST3
  09K       03/03/2012          TEST4
  098       05/01/2012          TEST5
  099       09/09/2012          TEST6
  2YT       08/25/2012          TEST7
  </code></pre>
  
  <p><strong><code>NUMBERS</code> table</strong></p>
  
  <pre><code>Dates              Amount
  10/10/2018         25.10
  08/31/2018         200.15
  05/10/2018         15.251
  03/03/2012         10.10
  05/10/2012         15.251
  08/31/2012         548.0          
  </code></pre>
  
  <p>I want the query to select all the values in the INFO table and find the closest or equal date in the Numbers table and give me the Amount. So my results would be:</p>
  
  <pre><code>ID        LockDate            Investor         Amount
  157       10/15/2018          TEST1            25.10
  VF1       09/02/2018          TEST2            200.15
  LO2       05/01/2018          TEST3            15.251
  09K       03/03/2012          TEST4            10.10
  098       05/01/2012          TEST5            15.251
  099       09/09/2012          TEST6            548.0
  2YT       08/25/2012          TEST7            548.0
  </code></pre>
  
  <p>By closest I mean equal or closest one whether it is <strong><em>lesser or greater</em></strong> than lock date.</p>
  
  <p>This is the query I'm using but it is just retrieving the greater or equal one which doesn't work at all for me since I have to do it dynamically...</p>
  
  <pre><code>SELECT I.* ,
         N.Amount  FROM 
  (
  SELECT  A.*, MIN(NUM.Dates) AS XDATE
  FROM INFO A
  INNER JOIN NUMBERS AS NUM
  ON NUM.Dates &gt;= A.LockDate
  GROUP BY A.ID
  )AS RES
  INNER JOIN NUMBERS AS N
  ON N.Dates = I.XDATE  
  </code></pre>
  
  <p>I will appreciate any help.</p>