码迷,mamicode.com
首页 > 其他好文 > 详细

完美解决distinct中使用多个字段的方法

时间:2015-03-06 15:42:57      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

众所周知,distinct可以列出不重复的记录,对于单个字段来说distinct使用比较简单,但是对于多个字段来说,distinct使用起来会使人发狂。而且貌似也没有见到微软对distinct使用多字段的任何说明。下面就提供了一种方法可以在使用distinct的时候同时使用多个字段。

select 要使用字段1,要使用字段2 from 表名 where id in (select min(id) from 表名 group by 不重复字段名)
例:
  select byid,id from bbs where id in (select min(id) from bbs group by byid)

select * from table where id in (select min(id) from table group by a,b,c)

完美解决distinct中使用多个字段的方法

标签:

原文地址:http://www.cnblogs.com/q149072205/p/4318133.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!