title: SQL - Multiple select filter: Combine filter conditions to get proper results
body: <p>I'm working on a filter where the user can choose different conditions for the end output. Right now I'm doing the construction of the SQL query, but whenever more conditions are selected, it doesn't work.</p>
  
  <p>Example of the <strong>advalues</strong> table.</p>
  
  <pre><code>+----+-----------+---------------+------------+
  | id | listingId | value         | identifier |
  +----+-----------+---------------+------------+
  | 1  | 1a        | Alaskan Husky | race       |
  +----+-----------+---------------+------------+
  | 2  | 1a        | Højt          | activity   |
  +----+-----------+---------------+------------+
  | 3  | 1c        | Akita         | race       |
  +----+-----------+---------------+------------+
  | 4  | 1c        | Mellem        | activity   |
  +----+-----------+---------------+------------+
  </code></pre>
  
  <p>As you can see, there's a different row for each advalue.</p>
  
  <p><strong>The outcome I expect</strong></p>
  
  <p>Let's say the user has checked/ticked the checkbox for the race where it says "Alaskan Husky", then it should return the <strong>listingId</strong> for the match (once). If the user has selected both "Alaskan Husky" and activity level to "Low" then it should return nothing, if the activity level is either "Mellem" or "Højt" (medium, high), then it should return the listingId for where the race is "Alaskan Husky" only, not "Akita". I hope you understand what I'm trying to accomplish.</p>
  
  <p>I tried something like this, which returns nothing.</p>
  
  <pre><code>SELECT * FROM advalues WHERE (identifier="activity" AND value IN("Mellem","Højt")) AND (identifier="race" AND value IN("Alaskan Husky"))
  </code></pre>
  
  <p>By the way, I want to select distinct listingId as well, so it only returns unique listingId's.</p>
  
  <p>I will continue to search around for solutions, which I've been doing for the past few hours, but wanted to post here too, since I haven't been able to find anything that helped me yet. Thanks!</p>