title: How to convert values of a table into fields in the resultant table of LEFT join
body: <p>I need some help with SQL query. I've no experience with structured DB like SQL. I've been googling this but not getting a proper answer. I've three main tables:</p>
  <p>Table1:</p>
  <pre class="lang-sql prettyprint-override"><code>+----+---------+-----+
  | id |  name   | age |
  +----+---------+-----+
  |  1 | Tarun   |  23 |
  |  2 | John    |  26 |
  |  3 | Rita    |  22 |
  |  4 | George  |  28 |
  |  5 | Mira    |  25 |
  |  6 | Jessica |  27 |
  |  7 | Robert  |  24 |
  +----+---------+-----+
  </code></pre>
  <p>Table2:</p>
  <pre class="lang-sql prettyprint-override"><code>+----+--------+
  | id |  sex   |
  +----+--------+
  |  1 | male   |
  |  3 | female |
  |  5 | female |
  |  6 | female |
  |  7 | male   |
  +----+--------+
  </code></pre>
  <p>Devices:</p>
  <pre class="lang-sql prettyprint-override"><code>+----+-------------+
  | id |   device    |
  +----+-------------+
  |  1 | spo2        |
  |  5 | thermometer |
  |  6 | spo2        |
  |  7 | BPmachine   |
  +----+-------------+
  </code></pre>
  <p>I want to join them and create a CustomTable in such a way that the values of Device column becomes the field name in the final CustomTable and values are set TRUE or FALSE accordingly:</p>
  <p>CustomTable</p>
  <pre class="lang-sql prettyprint-override"><code>+----+---------+--------+-------+-------------+-----------+
  | id |  name   |  sex   | spo2  | thermometer | BPmachine |
  +----+---------+--------+-------+-------------+-----------+
  |  1 | Tarun   | male   | TRUE  | FALSE       | FALSE     |
  |  5 | Mira    | female | FALSE | TRUE        | FALSE     |
  |  6 | Jessica | female | TRUE  | FALSE       | FALSE     |
  |  7 | Robert  | male   | FALSE | FALSE       | TRUE      |
  +----+---------+--------+-------+-------------+-----------+
  </code></pre>
  <p>Here is the incomplete query that I'm trying:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT
      t1.id as id, 
      t1.name as name, 
      t2.sex as sex, 
      d.device as device 
  FROM 
      Table1 t1 
  LEFT JOIN Table2 t2 ON d.id = t1.id 
  LEFT JOIN ??????????
  </code></pre>
  <p>I'm sorry for posting a messed up query. That's why I need your help. Please help me.</p>