title: SQL Query for Counting Values in a Set Column
body: <p>I dont know if this is possible with one query, but here goes:</p>
  
  <p>I have a column that is a set datatype.  I want to select a count of each possible value of the set.  So I have:</p>
  
  <p>row 1 set column value: 'opt 1','opt 2'</p>
  
  <p>row 2 set column value: 'opt 1', 'opt 3'</p>
  
  <p>row 3 set column value: 'opt 3','opt 4','opt 2'</p>
  
  <p>I need a query that will produce a structure similar to (doesnt have to be exactly this, just a count for each possible value of the set):</p>
  
  <pre><code>Array(
      [0] =&gt; Array(
          'value'=&gt;'opt 1',
          'count'=&gt; 2
      ),
      [1] =&gt; Array(
          'value'=&gt;'opt 2',
          'count' =&gt; 2
      ),
      [2] =&gt; Array(
          'value'=&gt;'opt 3',
          'count' =&gt; 2
      ),
      [3] =&gt; Array(
          'value'=&gt;'opt 4',
          'count' =&gt; 1
      )
  )
  </code></pre>