title: mysql - joining three tables with HAVING
body: <p>I have table:  </p>
  
  <pre><code>id name type
  </code></pre>
  
  <p>where "type" is 1 or 2</p>
  
  <p>I need to join this table with two other. Rows with "type = 1" should be joined with first table, and =2 with second.</p>
  
  <p>For example, main table contains some events that peoples did. Fist table to join is information about mans, and second is about women. Type is sex.<br>
  I need take last 10 events with all information about these peoples.</p>
  
  <p>Something like</p>
  
  <pre><code>SELECT *
  FROM tbl
  INNER JOIN tbl_1 ON tbl.name = tbl_1.name HAVING tbl.type = 1
  INNER JOIN tbl_2 ON tbl.name = tbl_2.name HAVING tbl.type = 2
  </code></pre>
  
  <p>But it does not working.<br>
  How it can be implemented?</p>