开发者

Stored Procedure to query value of one column in First Table to Match any value in Second Table?

开发者 https://www.devze.com 2023-01-17 20:34 出处:网络
I wrote this but it only returns exact matchs such as \'Carburetor\' not \'Brand X Carburetor\' Any help would be greatly appreciated!

I wrote this but it only returns exact matchs such as 'Carburetor' not 'Brand X Carburetor' Any help would be greatly appreciated!

SELECT [Col]
 FROM a 
 WHERE ([Col]) IN
  (   SELECT [col]
      FROM B
  )
UNION ALL
   SELECT Di开发者_Python百科stinct [col]
   FROM B
   WHERE  ([col]) IN
    (
       Select [col]
       FROM A 
    )


Using SQL Server, you might try as follow.

SELECT  a.[Col] 
FROM    a  
        INNER JOIN b ON a.Col LIKE '%' + b.Col + '%'
UNION ALL 
SELECT  Distinct b.[col] 
FROM    b
        INNER JOIN a ON b.COL LIKE '%' + a.Col + '%'
0

精彩评论

暂无评论...
验证码 换一张
取 消