简体   繁体   English

MYSQL:选择排序最低的记录

[英]MYSQL: select records with lowest sort

I have this table: 我有这张桌子:

ID | product | image | sort
---------------------------
1  |   1     |  img1 |  1
2  |   1     |  img2 |  1
3  |   1     |  img3 |  2
4  |   2     |  img4 |  1
5  |   2     |  img5 |  2

how can I select the records with lowest sort and lowest id grouping by product? 如何选择按产品排序和ID分组最少的记录?

the result that I would like to get is the following: 我想要得到的结果如下:

ID | product | image | sort
---------------------------
1  |   1     |  img1 |  1
4  |   2     |  img4 |  1

尝试这个:

Select * from table WHERE = (Select MIN(sort) from table) ORDER BY ID ASC group by product

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM