MySQL – How to Return the Date of Max ID

maxMySQL

I want to select the max id_product and date that corresponds to this max id.
my problem is that it returns the max id_ product with a different date.

I can't use the max(date) because it will return always the max what i need is the date of this max id.

This my query :

 SELECT 
   MAX(id_product),
   `date` 
 FROM `products` 
 WHERE `fk_stat` = '1' and `id_order` = '77185' ;

The result:

enter image description here

But the value that's must return:

09/07/2015 for id = 152752

enter image description here

Thanks for your help.

Best Answer

You don't need a subquery for this. It can be simple and more efficient:

SELECT id_product, date  
FROM products
WHERE fk_stat = 1
  AND id_order = 77185 
ORDER BY id_product DESC
LIMIT 1 ;