title: Retrieve specific value if set, or general if not
body: <p>I have to write a query which will import some data from table. Table structure is like:</p>
  
  <ul>
  <li>Item_ID</li>
  <li>Plant</li>
  <li>Price</li>
  </ul>
  
  <p>I have second table with</p>
  
  <ul>
  <li>Item_ID</li>
  <li>Plant</li>
  </ul>
  
  <p>Second table is a key, and I have to match rows from first table to get valid price. Seems to be easy, however:
  In first table column plant might determinate specific plant, or have value 'ALL'. What I want to do is retrieve price for given plant, if it is set, or get price for value 'ALL' if there is no row for given plant. In other words:</p>
  
  <pre><code>If first.Plant = second.Plant
    return price
  Else If first.Plant = 'ALL'
    return price
  Else
    return NULL
  </code></pre>
  
  <p>I can't use simple <code>ON first.Plant = second.Plant OR first.Plant = 'ALL'</code>, because there might be two rows: one for given plant and second for rest with value 'ALL'. I need to return only first price in that case. E.g.</p>
  
  <pre><code>Item_ID  | Plant  | Price 
    2      |   M1   |  10,0
    2      |  All   |  12,0
    1      |  All   |  9,0
  </code></pre>
  
  <p>In that case for Item_ID = 2 and Plant = M1 <strong>the only</strong> valid price = 10, but for Item_ID = 2 and Plant = M2 price =  12, and for any Item_ID = 1 price = 9</p>
  
  <p>I hope You understood something after my explanation ;) </p>