SELECT query return 1 row from each group

后端 未结 3 1266
囚心锁ツ
囚心锁ツ 2020-11-27 20:45

This is a product table and have few million of records.

\"enter

I want to lis

3条回答
  •  情书的邮戳
    2020-11-27 21:23

    SELECT store_id,id,product_name FROM table_name
    WHERE id IN (SELECT MAX(id) FROM table_name GROUP BY store_id)
    ORDER BY id
    

    this should work and you can Order by as per your req either by store_id or id.

提交回复
热议问题