日期:2014-05-17  浏览次数:20678 次

SQL去除重复行
比如有如下的数据格式:
user_id product_id
12 67
12 90
345 4
12 90
12 90
23 90
  发现第2行、第4行、第5行重复了,都是 12 90。 于是要去掉一个,只保留一个,即最后的输出应该为:
user_id product_id
12 67
12 90
345 4
23 90


该怎么写呢?
我的写法:select distinct user_id,product_id from table group by product_id

但是好像不太对。

------解决方案--------------------
group by product_id去掉就行。

------解决方案--------------------
把group by 后面去掉就行了
------解决方案--------------------
用disintct 可以
------解决方案--------------------
select distinct user_id,product_id from table

不要分组
------解决方案--------------------
这里去掉Group By product_id

直接查就行 select distinct user_id,product_id from table