Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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
4 answers

Browse Categories

...