ParisTheDog wrote:
I am trying to figure how to make a single select query in one table between
two fields to see if they are similiar. I need the second one to have a
wildcard. I can easily do this with no wildcard to see if they are the same
but I can't get anything to work when it should be LIKE.
Example:
Table: test
Field1 = "testing 123"
Field2="testing"
I need something that selects that row because the word "testing" is in
both. Hope this makes sense.
Assume we have a table like this:
mysql> select * from tepulis;
+-------------+---------+
| a | b |
+-------------+---------+
| testing 123 | testing |
| car | horse |
+-------------+---------+
2 rows in set (0.01 sec)
We can now search every row where content of b is found anywhere in the
middle of a by:
mysql> select * from tepulis where a like concat('%', b, '%');
+-------------+---------+
| a | b |
+-------------+---------+
| testing 123 | testing |
+-------------+---------+
1 row in set (0.00 sec)
Or if we only want those rows where the start of a is same as in b, we
can say:
mysql> select * from tepulis where a like concat( b, '%');
+-------------+---------+
| a | b |
+-------------+---------+
| testing 123 | testing |
+-------------+---------+
1 row in set (0.01 sec)
I think you got the point?
See mysql manual about string functions to learn more:
http://www.mysql.com/doc/en/String_functions.html