title: MySQL WHERE statement with cross table comparisons
body: <p>The MySQL statement below gives me three times the same result because I need to select all the data from the different tables to do the comparisons. How can I tell MySQL that I only need one of those entries?</p>
  
  <pre><code>SELECT watchedItems.id FROM watchedItems, globalItems, bidGroups 
  WHERE (watchedItems.bidGroupID IS NULL OR (watchedItems.bidGroupID IS NOT NULL AND bidGroups.bidGroupQty &gt; 0))
  AND watchedItems.aid = globalItems.aid
  AND watchedItems.maxPrice &gt; globalItems.currentPrice
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>ID
  2
  2
  2
  </code></pre>