title: How do I compare (AND) two strings which represent a binary mask in mysql?
body: <p>I have a table in mysql which stores (among other columns) a bitmask as a string, for example:</p>
  
  <p><code>000100</code></p>
  
  <p>I'd like to perform a query which will <code>AND</code> these fields together to provide a result that shows when any two mask positions are <em>both</em> true.</p>
  
  <p>As an example, consider these three sample records:</p>
  
  <pre><code>id  name  mask
  ==  ====  ====
  11  a     000100
  12  a     000110
  13  a     010000
  </code></pre>
  
  <p>This query is a self-join. I am looking for records where, for a given <code>name</code>, the same bitmask occurs twice or more.</p>
  
  <p>In the above example, the only records that match this condition are <code>11</code> and <code>12</code> (the fourth bit is <code>1</code> in both cases).</p>
  
  <p>The problem I am having is performing the <code>AND</code> on the mask. Since it is stored as a string, I am unsure how to get mysql to treat it as a binary value.</p>