title: mysql query with AND, OR and NOT
body: <p>Lets say I have a table of articles with as many to many relationship with topics. Each topic assigned to an article has a <code>type</code> field which can contain 1 of 3 values <code>AND</code>, <code>NOT</code>, and <code>OR</code>.</p>
  
  <pre><code>Articles
     id
     ....
  
  Topics
     id
     ....
  
  ArticleTopics
     article_id
     topic_id
     type
  </code></pre>
  
  <p>I want to create a query that says returns all articles that have:</p>
  
  <pre><code>ALL of the following topics: 1, 2, 3 (AND association)
     AND
  ANY of the following topics: 4, 5, 6 (OR association)
     AND
  NONE of the following topics 7, 8 (NOT association)
  </code></pre>
  
  <p>How do I go about creating this query?</p>
  
  <p>Thanks in advance!</p>