title: SELECT MIN value with GROUP BY and INNER JOIN?
body: <p>I have a query pulling data from 4 different tables;</p>
  <pre><code>SELECT cd.name, tt.card_number, tt.deck_count, tcg.url, MIN(tcgp.marketPrice) as 'price'
  FROM card_occurrences tt
  INNER JOIN card_database cd ON tt.card_number = cd.id
  INNER JOIN tcgplayer_cards tcg ON cd.name = tcg.name
  INNER JOIN tcgplayer_set_prices tcgp ON tcgp.productId = tcg.productID
  GROUP BY tt.card_number
  ORDER BY tt.deck_count DESC LIMIT 100
  </code></pre>
  <p>However, the <code>tcg.url</code> is wrong and I know it's a result of using <code>MIN(tcgp.marketPrice)</code> with <code>GROUP BY</code>.</p>
  <p>If I exclude the <code>MIN</code> and `GROUP BY then I get the ungrouped results like so:
  <a href="https://i.stack.imgur.com/WMbHS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WMbHS.png" alt="enter image description here" /></a></p>
  <p>However, when I do <code>MIN</code> with <code>GROUP BY</code> then I am correctly getting the lowest price but the URL is wrong. It's getting the first one found.
  <a href="https://i.stack.imgur.com/GS9vM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GS9vM.png" alt="enter image description here" /></a></p>
  <p>I think I need to use another JOIN statement (or maybe a subquery?) but I'm not entirely sure. Some prodding in the right direction is welcome!</p>