title: monetdb sql method to locate or match by the nearest value, without a TOP or LIMIT
body: <p>i am trying to replicate <a href="https://stackoverflow.com/questions/3291252/sql-query-join-nearest-date">this question</a> in monetdb, which i don't believe supports the TOP command and can only use LIMIT on the outermost result.</p>
  
  <p>if i could use <code>TOP</code> then i believe this command would give me what i want.  is there a reasonable alternative that's not massively inefficient?  i need to run this on a table that will quickly max out my server's ram.  thanks!</p>
  
  <pre><code>CREATE TABLE nearest_matches AS 
      ( SELECT a.* ,  
          (
              SELECT TOP 1 svcmon
              FROM person_table AS z
              WHERE a.yr = z.yr AND a.person_id = z.person_id
              ORDER BY abs( z.svcmon - a.svcmon )
          ) AS nearest_month
      FROM event_table AS a ) WITH DATA 
  </code></pre>