nsivakr
nsivakr

Reputation: 1595

Using like with multiple strings from a query

How to write a query to handle substring?

It is easy to do with in as long as the entire string need to be matched. However, how do we handle the same with partial strings?

select *
from dbo.mastertable
where string in ( select string from dbo.slave )

Upvotes: 0

Views: 912

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

You can use exists for a partial string match. I'm not sure what the exactly logic this, but the idea is:

select *
from dbo.mastertable m
where exists (select 1
              from dbo.slave s
              where s.string like '%' + m.string + '%'
             );

This means that the slave.string contains master.string.

Upvotes: 2

Related Questions