title: MySql. One column, two different data types, multiple where query
body: <p>I have got a mysql table structure:</p>
  
  <pre><code>uid     company     value
  </code></pre>
  
  <p>Description:<br>
  uid -> unical id<br>
  company -> four letters code of company ie. <code>AAAA</code>, <code>BIEW</code><br>
  value -> is a code of two different type of data: country or region, where:<br>
  country: <code>"/[0-9]+\-/"</code>, ie. <em>49-</em>, character at the end <code>-</code> means this is a region value<br>
  region: <code>"/[0-9]+\_[0-9]+/"</code>, ie. <em>49_002</em> , <em>49_4</em>, character <code>_</code> means this is a country value<br></p>
  
  <p>Now I want to SELECT all records WHICH:</p>
  
  <ul>
  <li>has a multiple company definitions, ie. <code>AAAA' OR 'BIEW'</code></li>
  <li>has a multiple country definitions, ie. <code>'49-' OR '5698-'</code></li>
  <li>first of countries above has specified region. I wan to search <code>49_01</code> only but not <code>49_03</code> and <code>49_965</code>, which also "belongs" to <code>49-</code> country</li>
  <li>second of countries <code>'5698-'</code> don't have specified regions and should return only records where <code>value='5698-'</code></li>
  </ul>
  
  <p>The <code>AAAA</code> company has 'filter' that specify country/region records but <code>BIEW</code> has not any specified country/region values. The MYSQL query don't work properly:</p>
  
  <pre><code>SELECT * FROM `table` WHERE (company='AAAA' OR company='BIEW') AND (value='5698-' OR value='49_01')
  </code></pre>