这句SQL怎么写?

imfine 2003-04-22 01:24:00
table1
id title content
1 aa a1a1
2 bb b2b2
3 cc c3c3
4 dd d4d4
.........
table2
id sid name
1 1 w
2 1 n
3 2 q
........
table2中的sid中存table1中的id,table1和table2是一对多的关系,2个表都做了全文索引,现在根据关键字在2个表中查询,要求返回tabl1的title,content,table2中对应table1的name

也就是一条记录对应多个附件的全文检索问题,请大家帮忙
...全文
46 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
imfine 2003-04-22
  • 打赏
  • 举报
回复
ok
select table1.title,table1.content,table2.name from table1
inner join table2 on table1.id = table2.sid where contains(table1.*,'关键字') or contains(table2.*,'关键字')

给分
imfine 2003-04-22
  • 打赏
  • 举报
回复
CONTAINS 或 FREETEXT 谓词只能在一个表上操作。请用表名来限定 * 的使用。
imfine 2003-04-22
  • 打赏
  • 举报
回复
我先试试
CrazyFor 2003-04-22
  • 打赏
  • 举报
回复
要不重复,只要保证派生的表2里的记录不重复。如:

select table1.title,table1.content,tem.name from table1
inner join (select sid,name from table2 group by sid,name)tem on table1.id = tem.sid where contains(*,'关键字')
imfine 2003-04-22
  • 打赏
  • 举报
回复
这样写行吗?重复的记录会去掉吗?
select table1.title,table1.content,table2.name from table1
inner join table2 on table1.id = table2.sid where contains(*,'关键字')
CrazyFor 2003-04-22
  • 打赏
  • 举报
回复
select table1.title,table1.content,table2.name from table1 table2
where table1.id = table2.sid and CONTAINS(.....
benxie 2003-04-22
  • 打赏
  • 举报
回复
select a.title,a.content,b.name from table1 a,table b where a.id=b.id
imfine 2003-04-22
  • 打赏
  • 举报
回复
最好是把检索的语句也一起写进来
imfine 2003-04-22
  • 打赏
  • 举报
回复
这只是取出对应的记录,检索后怎么根据检索结果取呢,也就是说,在table2中经过全文检索得到符合条件的记录,再取出对应table1中的记录,如果同时把相应的table1的记录也检索到了,又怎么去掉重复的
yoki 2003-04-22
  • 打赏
  • 举报
回复
select table1.title,table1.content,table2.name from table1 table2
where table1.id = table2.sid

or

select table1.title,table1.content,table2.name from table1
inner join table2 on table1.id = table2.sid

WOODHEAD_NET 2003-04-22
  • 打赏
  • 举报
回复
select table1.title,table1.content,table2.name from table1 join table2 on table1.id = table2.sid

34,587

社区成员

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

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