[MySQL]order by失效

失效语句:

获取的change_date不是最大值

select product_id, new_price, change_date
from (
  select product_id ,new_price, change_date
  from Products 
  order by change_date desc 
) as a
group by product_id 
 

生效语句:

增加distinct使order by生效

select product_id, new_price, change_date
from (
  select distinct(product_id) product_id, new_price, change_date
  from Products 
  order by change_date desc 
) as a
group by product_id 
 

你可能感兴趣的:(MySQL,order,by,by,排序,失效,无效)