title: How to UPDATE COLUMN with a condition FROM another table in SQL?
body: <p>I have 2 tables.</p>
  
  <p><strong>table1</strong></p>
  
  <pre><code>CATEGORY | RANGE    | PERCENTAGE
   REG     | 250001   | 50
   REG     | 500001   | 40
   REG     | 9999999  | 30
   VIP     | 5001     | 50
   VIP     | 10001    | 40
   VIP     | 9999999  | 30
  </code></pre>
  
  <p><strong>table 2</strong></p>
  
  <pre><code>CATEGORY | PRICE    | DISCOUNT
   REG     | 100000   |  0
   REG     | 400000   |  0
   REG     | 600000   |  0
   VIP     | 3000     |  0
   VIP     | 6000     |  0
   VIP     | 120000   |  0
  </code></pre>
  
  <p><br>
   I would like to update <code>DISCOUNT</code> in <code>table 2</code> based on <code>RANGE</code> and <code>PERCENTAGE</code> from <code>table 1</code></p>
  
  <p><strong>CATEGORY REG</strong><br></p>
  
  <pre><code>WHEN PRICE is  &lt;= 250001
  DISCOUNT = PRICE * 50%
  WHEN PRICE is  &gt; 250001 AND &lt;= 500001
  DISCOUNT = PRICE * 40%
  WHEN PRICE is  &gt; 500001
  DISCOUNT = PRICE * 30%
  </code></pre>
  
  <p><br>
  <strong>CATEGORY VIP</strong><br></p>
  
  <pre><code>WHEN PRICE is  &lt;= 5001 
  DISCOUNT = PRICE * 50% 
  WHEN PRICE is  &gt; 10001 AND &lt;= 500001
  DISCOUNT = PRICE * 40% 
  WHEN PRICE is  &gt; 100001
  DISCOUNT = PRICE * 30%
  </code></pre>