title: Conditionally select from one table or another in MySQL
body: <p>In MySQL, how do I select from another table if a foreign key is set?</p>
  
  <p>What I'm trying to do is select <code>Fields.value</code> if <code>Fields.value_id</code> isn't set, otherwise select <code>Values.value</code> from <code>Values</code> where <code>Value.id</code> is equal to <code>Fields.value_id</code>.</p>
  
  <p>My tables:</p>
  
  <p><code>Fields:</code></p>
  
  <p><code>id | value | value_id</code></p>
  
  <p><code>Values:</code></p>
  
  <p><code>id | value</code></p>
  
  <p>What's wrong with my code here? </p>
  
  <p>Code:</p>
  
  <p><code>SELECT CASE 
      WHEN Field.value_id = NULL OR Field.value_id = "" 
          THEN Field.value 
      ELSE 
          Value.value 
      FROM values as Value 
          WHERE (Field.value_id = Value.id)</code></p>