I need help with a probably simple SQL problem. quite new with SQL so not sure how to solve this. My problem is that i'm trying to select a columnA where the data in the column contains keywords from another columnB in tableB. an example of how the data is as below.
tableA, columnA : {'This apple is red', 'This ball is round', 'This chair is metal'}
tableB, columnB : {'red', 'round'}
Now im thinking something like this query
SELECT columnA FROM tableA
WHERE columnA LIKE '%' + (SELECT columnB FROM tableB) + '%'
So obviously it won't work because the subquery returns more than 1 value. I'm trying to see some other functions to use like CURSOR but I can't figure it out. Help is very appreciated, thank you.
Use EXISTS
instead:
SELECT columnA FROM tableA A
WHERE EXISTS (SELECT 1 FROM tableB B where A.columnA LIKE '%' + B.columnB + '%')
You can try this:
select * from tableA A
JOIN tableB B on A.columnA like '%' + B.columnB +'%'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.