0

我在尝试运行此全文搜索查询时遇到问题。我需要对两个表进行全文搜索。如果任何一个表中有任何条款,我需要从第一个表中返回记录。

select R.* from Request R 
    inner join Patients P on R.PatientID = P.PatientID
    inner join containstable(Request,(*),@keywords)AS KEY_TBL 
    ON R.RequestID = KEY_TBL.[Key] 
    full outer join 
    (select R.* from Request R 
    inner join Patients P on R.PatientID = P.PatientID
    inner join containstable(Patients,(*),@keywords) AS KEY_TBL2 
    ON P.PatientID = KEY_TBL2.[Key]) as b on R.RequestID = b.RequestID
4

1 回答 1

1

我所需要的只是一个联合而不是一个完整的外部连接。

select R.* from Request R 
    inner join Patients P on R.PatientID = P.PatientID
    inner join containstable(Request,(*),@keywords)AS KEY_TBL 
    ON R.RequestID = KEY_TBL.[Key] 
    UNION
    select R.* from Request R 
    inner join Patients P on R.PatientID = P.PatientID
    inner join containstable(Patients,(*),@keywords) AS KEY_TBL2 
    ON P.PatientID = KEY_TBL2.[Key]
于 2012-11-27T18:49:45.150 回答