注册 登录
编程论坛 ASP技术论坛

求助 select union 去重排序

maprincesse 发布于 2013-06-12 08:20, 647 次点击
我有2个表title和content,结构如下
title
id    board_id    report_date    title
content
id    board_id    report_date    inid    content
其中content为title的子内容,用inid标志,如所有inid=8的内容就是title中id=8内容的子内容,同时再更新时更新子内容会把子内容的最新日期即report_date与title的一致,即title的report_date与content的最后report_date是一样的,board_id都是一致的,

现在我要查询的为title中和content中包含关键字keyword的记录,同时去掉重复记录并按照日期降序排列,(因为id=8和inid=8实际上是一条记录,)
我写的是这样的,但是不能去重
select id as titleid,board_id,report_date fromtitle where title like '%&keyword&%' union select inid as titleid, board_id, report_date from content where  id in (select max(id) where content like '%&keyword&%' and group by inid) order by report_date desc
这样写的时候会造成如果title和content均含有keyword时会出现2条记录
该怎么写呢???
0 回复
1