How would you use 'LIKE' to search in a subquery?
E.g. i've tried doing this, but doesn't work:
SELECT *
FROM mytable
WHERE name
LIKE '%
(SELECT name FROM myothertable)
%'
I have this so far:
SELECT * FROM t1
WHERE t1.name IN (SELECT t2.name FROM t2)
AND (t1.title IN (SELECT t2.title FROM t2)
OR t1.surname IN (SELECT t2.surname FROM t2))
It's working ok as it returns exact matchs, but it doesn't seem to return my other records that are similar, so I would like to also check that:
t1.title LIKE '%t2.title%' AND t1.surname LIKE '%t2.surname%'
How would i do this?
It Worked FOR ME
Best way would be to create function called NameMatch()
Final Query :
The function would look like :
Using a JOIN:
...but there could be duplicates, if there's more than one match in
myothertable
for a givenmytable
record.Using EXISTS:
Using Full Text Search
MATCH
(requiresmyothertable
is MyISAM)For example:
As far as terminology goes: this is known as a correlated subquery.
this string works fine for me.
"SELECT * FROM table1 WHERE field like CONCAT('%', (SELECT id FROM table2), '%')";
Just another way: