title: MySql check is values exists then return them as different columns
body: <p>I don't have the words to search / explain this query so I am asking on here. So I have Table A which stores several records for a user using <code>user_id</code>. I want to return rows that define if the user has a one of the color values present. </p>
  
  <pre><code>Table A 
  id | user_id | color
  1  | 34      | red 
  2  | 34      | blue
  3  | 50      | red
  4  | 34      | green
  5  | 77      | red
  6  | 8       | red
  7  | 77      | green
  </code></pre>
  
  <p>What I want to return based on the table above. 1 being the records exists and 0 being it does not.</p>
  
  <pre><code>user_id | red | blue | green
  34      |1    | 1    | 1
  50      |1    | 0    | 0
  77      |1    | 0    | 1
  8       |1    | 0    | 0
  </code></pre>
  
  <p>So essentially what I am trying to accomplish is figure out all the distinct values that the <code>color</code> column has in table A, then select which values each user_id is has and display it in one row per user. The issue I am having is doing this in one shot without knowing beforehand what the values in the <code>color</code> column are.</p>