title: mysql 6 tables join together in one query
body: <p>I have 6 tables: users, journals, files, flags, flag_details</p>
  
  <pre><code>users (id, avatar, fullname)
  journals (id, container, container_id, user_id, title)
  files (id, container, container_id, user_id, title)
  flags (id, container, container_id, total)
  flag_details (id, container, container_id, reason, comment, user_id)
  trend_item (id, container, container_id, user_id)
  </code></pre>
  
  <p>Relation is:</p>
  
  <pre><code>if(flags.container='look') then flags.container_id = journals.id
  </code></pre>
  
  <p>So I take all records from journals table</p>
  
  <pre><code>if(flags.container='photo') then flags.container_id = files.id
  </code></pre>
  
  <p>So I take all records from files table</p>
  
  <pre><code>if(flags.container='trend') then flags.container_id = trend_item.id
  </code></pre>
  
  <p>So I take all records from trend_item table</p>
  
  <p>So my view to be like this:</p>
  
  <pre><code>id | container | things      | total flag
  1  | look      | 123 - guy   | 2
  2  | photo     | 321 - budi  | 4
  3  | trend     | 345 - elvis | 3
  4  | look      | 876 - cans  | 6
  </code></pre>
  
  <p>So I got the query like this:</p>
  
  <pre><code>SELECT DISTINCT (id), created_at, container, IF( container =  'look', (
  
  SELECT a.container_id
  FROM flags a, journals b
  WHERE a.container_id = b.id
  ), IF( container =  'photo', (
  
  SELECT a.container_id
  FROM flags a, files b
  WHERE a.container_id = b.id
  ), (
  
  SELECT a.container_id
  FROM flags a, trend_items b
  WHERE a.container_id = b.id
  ) ) ) , total, 
  `status`
  FROM flags
  ORDER BY created_at DESC 
  </code></pre>
  
  <p>But answer is subquery return more than 1 row.</p>
  
  <p>There's any possible if all of that put together in one query?</p>