title: Find matching row in one table based on the value from second
body: <p>I am trying to figure out way to find a row based on the value from other table. Suppose I have a local table which stores Rating values and corresponding letter grades from S&amp;P and Moody's: </p>
  
  <pre><code>row_id  Moody's S&amp;P Moody's Rating Factor
  1   A1  A+  70
  2   A2  A   120
  3   A3  A-  180
  4   Aa1 AA+ 10
  5   Aa2 AA  20
  6   Aa3 AA- 40
  7   Aaa AAA 1
  8   B1  B+  2220
  9   B2  B   2720
  10  B3  B-  3490
  11  Ba1 BB+ 940
  12  Ba2 BB  1350
  13  Ba3 BB- 1766
  14  Baa1    BBB+    260
  15  Baa2    BBB 360
  16  Baa3    BBB-    610
  17  C   D   10000
  18  Ca  C   10000
  19  Ca  CC  10000
  20  Caa1    CCC+    4770
  21  Caa2    CCC 6500
  22  Caa3    CCC-    8070
  23  NR  NR  10000
  </code></pre>
  
  <p>My second table stores Rating values for several products, e.g.</p>
  
  <pre><code>item    value
  12345   2113.48869296578
  </code></pre>
  
  <p>And the rule here is: 2113 is between 2220 and 1766, so I should take the lower grade which is BB- which is in 13th row. </p>