Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple conditions on same column
    text
    copied!<p>Have seen multiple posts on this but I can't see any which answer my question.</p> <p>Basically I have 3 tables in my database which relate to members and their categorisation/classification. </p> <ol> <li>members (defines list of members and associated data)</li> <li>member_taxonomy (defines categories, subcategories and facilities using combination of partent id and enumerated field tax_type (CATEGORY, SUBCATEGORY, FACILITY)</li> <li>member_taxonomy_map (defines mapping between members and member_taxonomy)</li> </ol> <p>I have a members page within which are a number of options to refine the search by specifying one or more subcategory and one or more facility. I have been trying to search on the table using the query:</p> <pre><code>SELECT members.* FROM (members) JOIN member_taxonomy_map ON member_taxonomy_map.member_id = members.id WHERE member_taxonomy_map.taxonomy_id = 1 AND member_taxonomy_map.taxonomy_id = 26 AND members.active = 1 AND members.deleted = 0; </code></pre> <p>However this returns 0 rows which is something to do with having multiple where clauses on the same column but I can't figure out how this query should look. Each time the search is refined (and there could be up to 30 different options to refine the search) I need add an additional AND clause so that only members with these mappings are returned.</p> <p>An IN clause will not work as this is effectively returning any rows which match any of these particular values but this is incorrect as it needs to match exactly the values specified.</p> <p>Hopefully someone can give me a few pointers in the right direction.</p> <p>Thanks in advance.</p> <p><strong>UPDATE</strong></p> <p>It is possible that taxonomy_id can be 1 and 26. I prob need to include the schema for the members_taxonomy_map table. </p> <pre><code>id int tax_name varchar slug varchar tax_type enum ('CATEGORY','CLASSIFICATION','FACILITY','RATING') parent_id int active int </code></pre> <p>Therefore any tax_type with no parent id set are top level CATEGORY. Subcategories have a parent_id CATEGORY. CLASSIFICATION's can have a parent_id of the CATEGORY and FACILITY's have a parent_id of CATEGORY.</p> <p>Therefore for example a category could be accommodation, sub-category could be hotel and facility could be wifi. Therefore if a member has all three of these items they will have 3 entries in the mapping table. I need to be be able to filter these so that it builds up the query to filter depending on the accommodation types (i.e subcategories - those entries with a tax_type of CATEGORY but also have a parent id, then within this the classifications. The query may return multiple entries for the same member but I can deal with this by filter these out with extra SQL clauses.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload