title: Pivot MySQL table setting boolean values
body: <p>I have to perform what I think is a very basic MYSQL table pivot, but I am completely new to sql so I am not sure about the syntax. I have the following table</p>
  <pre><code>record_id tag_id
  id_1      tag1
  id_1      tag2
  id_2      tag1
  id_2      tag3
  </code></pre>
  <p>I would like to obtain a pivoted table, whose rows are the unique record_ids, the columns are the unique tag_ids, and the values are boolean true/false if that record_id has that tag. In this case, the expected result would be:</p>
  <pre><code>record_id tag1  tag2  tag3
  id_1      true  true  false
  id_2      true  false true
  </code></pre>
  <p>How can I achieve this?</p>
  <p>Further question: what if I have another table that associates tag_names to tag_id, and I would like the columns of my pivoted table to be named after tag_names? In this example, starting from</p>
  <pre><code>tag_id tag_name
  tag1   tag_name1
  tag2   tag_name2
  tag3   tag_name3
  </code></pre>
  <p>I would finally get</p>
  <pre><code>record_id tag_name1  tag_name2  tag_name3
  id_1      true       true       false
  id_2      true       false      true
  </code></pre>
  <p>I appreciate any help.</p>