title: Selecting Max Value and Key mySQL
body: <p>I know this is probably a very simple fix, but I cannot get my mind wrapped around it. </p>
  
  <p>I have a table factproductsales that has sales for all transactions. I have to find which product has the highest sales. I have to give the productID and the amount. </p>
  
  <p>Here is what I have: </p>
  
  <pre><code>SELECT productid, MAX(salestotalcost) 
  FROM factproductsales
  </code></pre>
  
  <p>It gives me the right amount, but it gives me the wrong productid. It should be 5 but instead gives me 1. I think the mistake I am making is a very obvious one. Thanks for the help</p>