2017-09-13 63 views
0

在Sub查詢使用喜歡使用像在Sub查詢

表A

Part Description 
-------------------- 
Part1 Top Cover 
Part2 Botom Cover 
Part3 xxxx 
Part4 Cover 
Part5 yyyy 

表B

Keyword 
----------- 
Cover 

結果應該是

Part Description 
-------------------- 
Part1 Top Cover 
Part2 Botom Cover 
Part4 Cover 

我想知道在表中的部分具有描述爲掩護

我用下面的查詢

SELECT Part FROM TableA WHERE Description LIKE '%' + (SELECT Keyword FROM TableB ) + '%' 

回答

0

,所以你要匹配tableB的所有關鍵字。交叉連接在這裏是不錯的選擇。代替子查詢使用加入

select part 
from tableA, 
tableB 
where Description LIKE '%Keyword%'