mysql distinct 多列

来源:互联网 发布:js整数加减乘除 编辑:程序博客网 时间:2024/05/06 19:57

mysql  distinct 多列


很多时候,mysql中在使用distinct进行多列选择的时候,需要注意。如下:
表中数据如下:



我们使用正常的distinct选出单个的memo值。
select distinct memo,name from xytest.student;

结果如下:


为了得到单一的memo,我们需要使用这样的语句。
SELECT distinct memo,name from xytest.studentwhere id in (select distinct min(id) from xytest.student group by memo)

运行上述语句会生成下图结果:

原创粉丝点击