Answer the question
In order to leave comments, you need to log in
mysql like by 2 columns
There are 2 tables:
tbl1
id value
- 1 abcde
2 abeer
3 kdfdsd
tbl2
id value
- 1 bc
2 asasar
3 kdf
How to write a query to select IDs whose tbl2.value values are included in tabl1.value. Logically, this is done through Like, but the problem is how to write the% symbols in the query?
SELECT `tbl1`.`id` FROM `tbl1`, `tbl2` WHERE `tbl1`.`value` LIKE `tbl2`.`value`
Answer the question
In order to leave comments, you need to log in
It seems to me like this:
Just in case: I hope you understand how resource-intensive such a request is and use it for some one-time selection “for yourself” and not in a combat application?
SELECT `tbl1`.`id` FROM `tbl1`, `tbl2` WHERE `tbl1`.`value` LIKE CONCAT('%',`tbl2`.`value`,'%')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question