Q:

Searching for sub-strings in mysql

I know that if I were to search for a substring in a mysql cell, I can do something like the following
Select * from table_name where column_name like '%search_string%';

How do I perform the search if the cell values are the search strings? For example, if I have the following table,
ID  String
1    abc
2    def
3    ghi

And I have the string "123abc567", I want to be able to search the table so I get the result ID = 1. What mysql statement should I use, or do I have to read row by row and then do a strstr() in my program?

A:

You do it pretty much similarly:
select * from table_name where '123abc456' like concat('%', column_name, '%');

see an example:
http://sqlfiddle.com/#!9/e0fce/1/0
PS. remove the c++ tag because it's unrelated...

