title: mySQL SELECT values from a TABLE where the TABLE name is based on a field value
body: <p>Here's are very simplified versions of my tables.</p>
  
  <pre><code>[stock_adjust]
  id
  batch_table_name
  batch_id
  adjustment_reason
  qty
  
  [ingredient_batch]
  id
  batch_name
  ...lots of other columns
  
  [product_batch]
  id
  batch_name
  ...lots of other columns
  
  [packaging_batch 
  id
  batch_name
  ...lots of other columns
  </code></pre>
  
  <p><em>stock_adjust</em> contains the name of the correct batch table in the column <em>batch_table_name</em> which will either be "ingredient_batch", "product_batch" or "packaging_batch". I need to get the values from the correct batch table for each entry. The pseudo code for this would look something like the following:</p>
  
  <pre><code>SELECT sa.id, sa.adjustment_reason, sa.qty, batch.batch_name 
  FROM stock_adjust AS sa, [sa.batch_table_name] AS batch
  WHERE sa.batch_id=batch.id
  </code></pre>
  
  <p>I have tried to simplify the description and tables as much as possible, hopefully I haven't simplified it too much and the above makes sense?</p>
  
  <p>I have found several questions regarding similar issues to the following, but they either do not work correctly in this situation or I am not understanding the question correctly.</p>