所以你有三个人...
declare @persons table (id int identity(1,1), name varchar(10))
insert @persons (name) values ('Babs'),('Ken'),('Neville'),('Sue')
Babs 有 A 和 B,Ken 有 A 和 C,Neville 只有 B,Sue 只有 C
declare @personkeywords table (personid int, keyword varchar(5))
insert @personkeywords values (1,'a'),(1,'b'),(2,'a'),(2,'c'),(3,'b'),(4,'c')
搜索是 A 或 C
declare @searchkeywords table (searchid int, keyword varchar(5))
insert @searchkeywords values (1,'a'),(1,'c')
所以...
select distinct persons.*
from @persons persons
inner join @personkeywords personkeywords on persons.id = personkeywords.personid
inner join @searchkeywords searchkeywords on personkeywords.keyword = searchkeywords.keyword
where
searchkeywords.searchid = 1
给
1 Babs
2 Ken
4 Sue