0
Sql LIKE and IN together
Hi everyone. Pretty new to SQL so any help will be much appreciated. Is there a way to combine link and in into the following: SELECT year, centre FROM Data WHERE Centre LIKE IN (â%20-20%â, â%20-30%â); Does not work. Just need to get rows of data with centres with those texts in the string. Thanks
3 Answers
+ 4
You can think of 'IN' as a simplified chain of 'OR' expressions.
So you can write the query like this:
SELECT year, centre
FROM data
WHERE centre LIKE '%20-20%'
OR centre LIKE '%20-30%';
+ 3
Nope. There can be only a single WHERE clause. But you can use parentheses to group any number of conditions, like this:
WHERE year =18
AND (centre LIKE â%20-20%â
OR centre LIKE â%20-30%â) ;
+ 1
Thanks a lot that solved my query.