消除重复记录?

hebhd 2005-06-06 11:35:12
库结构
news:
cp_news_index cp_news_title cp_news_date
1 hebhd 2005
2 hebhd 2005
3 houzi 2005

问题
筛选出 cp_news_title不同的记录
也就是返回结果集
1 hebhd 2005
3 houzi 2005


2 hebhd 2005
3 houzi 2005

我用 select distinct cp_news_title from news 只能取 cp_news_title 字段
如何才做到呢?
...全文
123 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
phantomMan 2005-06-07
  • 打赏
  • 举报
回复
这样写效率更高,不使用group by:
select cp_news_index,distinct cp_news_title,cp_news_date from news
因为group by 要进行分组
fengfangfang 2005-06-06
  • 打赏
  • 举报
回复
select min(cp_news_index), cp_news_title, cp_news_date
from news
group by cp_news_title, cp_news_date


select max(cp_news_index), cp_news_title, cp_news_date
from news
group by cp_news_title, cp_news_date

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧