Sql LIKE and IN together | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

26th Mar 2019, 1:29 PM
Adnan Mansoor Yousaf
Adnan Mansoor Yousaf - avatar
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%';
26th Mar 2019, 8:12 PM
Tibor Santa
Tibor Santa - avatar
+ 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%’) ;
26th Mar 2019, 8:49 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Thanks a lot that solved my query.
26th Mar 2019, 8:51 PM
Adnan Mansoor Yousaf
Adnan Mansoor Yousaf - avatar