I need help with a WHERE/LIKE clause inside a select statement. I want it to return values from table1.results WHERE/LIKE the table2.selection column contains all the characters from the table1.data column.
If the selection column had the characters “abc” and the data column had “bc” than it could be a match. If the selection column had “abc” and the data column had “abcd” than it wouldn’t be a match as the selection column was missing “d”.
I’ve tried different operators and regexp and can’t figure it out.
Table1:
wdt_id | data | results
1 | abcd | Mazda
2 | abde | Toyota
3 | ace | Honda
Table2:
wdt_id | selection | selection_results
1 | abde | null
2 | abcd | null
3 | ab | null
Statement:
SELECT results
FROM table1
WHERE table1.data LIKE concat(‘%’,table2.selection,'%');
Edit: I’m added some data above. The select statement is part of a large UPDATE Trigger. The trigger updates the selection_results column. With the above data the selection result for row1 would be Toyota.