title: How do i get the most sold product for every month there is in the database
body: <p>So I have a database like this:</p>
  <p>product_table: (product_id, name),
  date_table: (date_id, day, month, year),
  sales_table: (sale_id, product_id, date_id, total_value)</p>
  <p>I need to get the most sold product for every month that exists in the &quot;date_table&quot; with one query, the only way I was able to do was specifing the month and year in the query, but then i gotta do one query for each month which is not what I need.</p>
  <p>Edit:</p>
  <p>here is the query i have written:</p>
  <pre><code>SELECT p.name, d.month, d.year, SUM(s.total_value) as total
  FROM sales_table s
  INNER JOIN product_table p ON s.product_id = p.product_id
  INNER JOIN date_table d ON s.date_id = d.date_id
  WHERE d.month = &quot;$month&quot; AND d.year = &quot;$year&quot; 
  ORDER BY total DESC
  LIMIT 1
  </code></pre>
  <p>As i said, i have to give the month and the year i want here, but i need the most sold product (with the use of sales value in sales_table not the row count of product table) for every month in just one query!</p>