Is it possible to combine LIKE
and IN
in a SQL Server-Query?
So, that this query
SELECT * FROM table WHERE column LIKE IN ('Text%', 'Link%', 'Hello%', '%World%')
Finds any of these possible matches:
Text, Textasd, Text hello, Link2, Linkomg, HelloWorld, ThatWorldBusiness
etc...
Answer: There is no direct was to combine a like with an IN statement. However Oracle does support several alternative clauses: CONTAINS clause: the contains clause within context indexes.
Returns true if both expressions are true ; otherwise, false or NULL .
Not only LIKE, but you can also use multiple NOT LIKE conditions in SQL. You will get records of matching/non-matching characters with the LIKE – this you can achieve by percentile (%) wildcard character. Below use cases, help you know how to use single and multiple like conditions.
Note – Use of IN for matching multiple values i.e. TOYOTA and HONDA in the same column i.e. COMPANY. Syntax: SELECT * FROM TABLE_NAME WHERE COLUMN_NAME IN (MATCHING_VALUE1,MATCHING_VALUE2);
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%'
I know this is old but I got a kind of working solution
SELECT Tbla.* FROM Tbla INNER JOIN Tblb ON Tblb.col1 Like '%'+Tbla.Col2+'%'
You can expand it further with your where clause etc. I only answered this because this is what I was looking for and I had to figure out a way of doing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With