title: MySQL INNER JOIN to find the max value of group of rows
body: <p>I have put up a sample of what I'm trying to do here </p>
  
  <p><a href="http://sqlfiddle.com/#!2/514d2/2" rel="nofollow">http://sqlfiddle.com/#!2/514d2/2</a></p>
  
  <p>This demo finds all rows in the "bids" table that are NOT the highest bid per listing_id.  What I need to do though is find all the listings, where the $userid (in this case user 1) is the highest bidder.</p>
  
  <p>Can someone help me figure this out?</p>
  
  <p>For those that don't use SQLFiddle...</p>
  
  <ul>
  <li>Tablename: listings</li>
  <li>Tablename: bids</li>
  </ul>
  
  <p>SQL:</p>
  
  <pre><code>SELECT listings.end_date, 
      listings.user_id, 
      listings.title, 
      listings.auc_fp, 
      listings.id, 
      listings.auc_image1 
  FROM listings 
  INNER JOIN 
      (SELECT 
       listing_id, 
       user_id, 
       bid maxBid 
   FROM bids 
   WHERE bid 
   NOT IN 
       (SELECT MAX(bid) 
        FROM bids) 
        GROUP BY 
           listing_id, 
           user_id) 
      bids ON 
        listings.id = bids.listing_id 
    WHERE bids.user_id=1 
    AND listings.end_date &gt; NOW() 
    ORDER BY listings.list_ts DESC
  </code></pre>
  
  <p>This query successfully finds all the listings where the $userid has placed a bid, but is not the highest bidder.  I'd like to find all the listings where the $userid has placed a bid and IS the highest bidder.</p>