SQL,使用LIKE运算符从两个表中进行选择

问题描述 投票:1回答:3

table1.cloumn的值包含来自table2.column的值时,我需要从select * from Products1 where sku like '%' + (select sku from Products2) + '%' 中选择

我在尝试这个:

exists
sql sql-server sql-like
3个回答
5
投票

您可以尝试将select * from Products1 t1 where exists( select 1 from Products2 t2 WHERE t1.sku like '%' + t2.sku+ '%' ) 与子查询一起使用。

sqlfiddle

INNER JOIN


2
投票

其他答案的替代方法是使用SELECT P1.* FROM Products1 P1 INNER JOIN Products2 on P1.sku like '%' + P2.sku+ '%'

select t1.* 
from Products1 t1
where t1.sku like '%'+ (
      select t2.sku from Products2 t2
         )+ '%'

1
投票

使用简单就好

sample

qazxswpoi

© www.soinside.com 2019 - 2024. All rights reserved.