title: MySQL select based on ENUM values
body: <p>I have a a suppliers directory table in a MySQL database which has an associated suppliers mappings table.  This table maps the following criteria against an individual supplier:</p>
  
  <ol>
  <li>Services. </li>
  <li>Specialities </li>
  <li>Standards</li>
  </ol>
  
  <p>Just for background info each of these have values stored in 3 individual corresponding tables.  All services that can be provided by any supplier are listed in the services table and the the mapping table captures the services which are offered by an individual supplier.  A supplier can provide more than one service so they would have a mapping for each service they provide.  Same goes for specialities and standards.</p>
  
  <p>Where I am running into difficulties is on a search query where a user can query a list of suppliers on any one or all three of the above criteria.  So for example they can search for a supplier with service a, speciality b and standard c.  They can't search for multiple values on a service, speciality or standard</p>
  
  <p>My mappings table looks like the following:</p>
  
  <pre><code>id int(11) unsigned NOT NULL 
  supplier_id int(11) unsigned NOT NULL
  entity_type enum('KEY_SERVICE','STANDARD','SPECIALITY') NOT NULL
  entity_id int(11) NOT NULL 
  </code></pre>
  
  <p>Where entity_type maps is used to indicate the entity type being mapped and entity_id indicates the individual entity.  </p>
  
  <p>My query is as follows:</p>
  
  <pre><code>SELECT DISTINCT supplier_mappings.supplier_id, suppliers.company_name
  FROM supplier_mappings
  JOIN suppliers ON suppliers.id = supplier_mappings.supplier_id
  WHERE (supplier_mappings.entity_type = 'KEY_SERVICE' AND supplier_mappings.entity_id =    '55')
  AND (supplier_mappings.entity_type = 'SPECIALITY' AND supplier_mappings.entity_id = '218')
  AND (supplier_mappings.entity_type = 'STANDARD' AND supplier_mappings.entity_id = '15'); 
  </code></pre>
  
  <p>which should return all suppliers who have a key service with the id 55, a speciality with the id 218 and a standard with the id 15.  However it just returns an empty result set even though I know there is at least one supplier with these defined.  It appears to be something to do with the compounded AND clauses but can't figure out what.</p>
  
  <p>Would appreciate it if anyone has any ideas?</p>