title: MySQL join tables where table name is a field of another table
body: <p>I have 5 tables. One primary and 4 additional (they have different columns).</p>
  
  <ol>
  <li>objects</li>
  <li>obj_mobiles</li>
  <li>obj_tablets</li>
  <li>obj_computers</li>
  </ol>
  
  <p>Here is the structure of my main table (objects).</p>
  
  <blockquote>
    <p>ID  |  type  |  name  |  etc...</p>
  </blockquote>
  
  <p>So what I want to do is to join objects with other (obj_mobiles,obj_tablets,...) tables, depending on type field.
  I know that I should use dynamic SQL. But I can't make procedure. I think it should look like something like this.</p>
  
  <pre><code>SELECT objects.type into @tbl FROM objects;
  PREPARE stmnt FROM "SELECT * FROM objects AS object LEFT JOIN @tbl AS info ON object.id = info.obj_id"; 
  EXECUTE stmnt;
  DEALLOCATE PREPARE stmnt;
  </code></pre>
  
  <p>Aslo pseudo-code</p>
  
  <pre><code>SELECT * FROM objects LEFT JOIN [objects.type] ON ... 
  </code></pre>
  
  <p>Can anyone post procedure? Also I want to have all rows not just 1 row.
  Thanks.</p>