我们经常会遇到删除重复数据需要只保留一条的操作,那如果重复数据不删除,只显示一条怎么做呢,下面我们来介绍几种方法
假设有一张商品信息表,其中有字段商品ID,商品编号,等字段。
方法一
Select * FROM 商品信息表 AS a Where not Exists (select 1 from 商品信息表 where 商品编码=a.商品编码 an
方法二
Select a.*FROM 商品信息表 AS a INNER JOIN (Select min(商品ID) AS ID, 商品编码 FROM 商品信息表 GROUP BY 商品编码) AS b ON (a.商品ID=b.ID) AND (a.商品编码=b.商品编码);
方法三
Select * FROM 商品信息表 AS a Where 商品ID=(select min(商品ID) from 商品信息表 where 商品编码=a.商品编码);
方法四
Select * FROM 商品信息表 AS a Where 商品ID in(select min(商品ID) from 商品信息表 group by 商品编码);
附 件:
点击附件下载