title: MySQL Query Customers Who Have Not Bought
body: <p><strong>Background:</strong></p>
  <p>We are setting up a promotions system to give away free products to registered customers.  We're trying to design a database which is flexible enough to handle multiple products, and giveaways.  The requirements are that products may be given away on a drip basis on a first come basis to qualified customers.</p>
  <p><strong>Example:</strong></p>
  <p>Apple wants to give away 1000 ipads in March.</p>
  <p>They want to give away maximum of 1 per hour.</p>
  <p>They want to give it to customers who are in California or New York.</p>
  <p>They want to limit how many free ipads a customer can get (limit 1 per 15 days).</p>
  <p><strong>Data Structure:</strong></p>
  <ul>
  <li><p><strong>Products</strong> - 1 entry per unique product. e.g. Apple iPad</p>
  </li>
  <li><p><strong>ProductGiveAways</strong></p>
  <ul>
  <li>ProductID: AppleIpad</li>
  <li>Quantity:1000</li>
  <li>StartDate: 03/01/2014</li>
  <li>End Date 03/31/2014</li>
  <li>CustomerState: California,NewYork</li>
  <li>PurchaseLimitDays: 15</li>
  </ul>
  </li>
  </ul>
  <p><strong>Problem:</strong></p>
  <p>With the above structure we are able to do a query against our customers table and find out which are qualified for the promotion.</p>
  <p>What I cannot figure out is the best way to:</p>
  <ol>
  <li>Query customers in California or New York (is this a good use case for a join and another table?)</li>
  <li>When a customer logs in to see what free items are not available to him, how can I exclude the Apple iPad if the customer has already gotten this freebie?</li>
  </ol>
  <p>In other words:</p>
  <ul>
  <li><p>Say amazon.com wants to show me DVDs which I have not already bought.  What is the proper way to query that?</p>
  </li>
  <li><p>Is the right approach to first get a list of previously bought products and then Query with a NOT clause?</p>
  </li>
  </ul>