0 votes
1 view
in SQL by (6.1k points)

Can we combine LIKE and IN in a SQL Server-Query?

So, that the following query

SELECT * FROM table WHERE column LIKE IN ('Text%', 'Link%', 'Hello%', '%World%')

Will find any of the following possible matches: 

Text, Textasd, Text hello, Link2, Linkomg, HelloWorld, ThatWorldBusiness

 etc...

1 Answer

0 votes
by (12.7k points)

Effectively, the IN statement creates a series of OR statements... so

SELECT * FROM table WHERE column IN (1, 2, 3)

Is effectively 

SELECT * FROM table WHERE column = 1 OR column = 2 OR column = 3

And sadly, that is the route you'll have to take with your LIKE statements

SELECT * FROM table
WHERE column LIKE 'Text%' OR column LIKE 'Hello%' OR column LIKE 'That%'

Interested in SQL ? Check out this SQL Certification by Intellipaat. 

Related questions

0 votes
1 answer
asked Dec 5, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 21, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
asked Dec 17, 2020 in SQL by Appu (6.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...