mysql distinct 多列

mysql  distinct 多列


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



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

结果如下:


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

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


版权声明:本文为wild46cat原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。