Try this
Original Data:
name
Doe John
Stack Overflow
Pew Ned
Record to search
declare @String2Search varchar(50)
set @String2Search = 'John Doe'
Sql Sever Query
select name from @t
where REPLACE(name,' ','') like '%' + REPLACE(@String2Search,' ','') + '%'
OR
SUBSTRING(name,CHARINDEX(' ',name),len(name)) + SUBSTRING(name,0,CHARINDEX(' ',name)) like '%' + REPLACE(@String2Search,' ','') + '%'
MySql Query
select name from @t
where REPLACE(name,' ','') like '%' + REPLACE(@String2Search,' ','') + '%'
OR
SUBSTRING(name,LOCATE(' ',name),LENGTH(name)) + SUBSTRING(name,0,LOCATE(' ',name)) like '%' + REPLACE(@String2Search,' ','') + '%'
Note- I am a sql server guy. so first I wrote the query in SQL SERVER and then I checked in google for the corresponding function equivalence in MYSQL and I just replaced those
like
SQLSERVER ---------------------------------------------- MYSQL
SUBSTRING() ------------Equivalent----------------------- SUBSTRING()
CHARINDEX() ------------Equivalent----------------------- LOCATE()
REPLACE() --------------Equivalent----------------------- REPLACE()
LEN() --------------Equivalent----------------------- LENGTH()
In Sql Server it is working fine. The concept I implemented is I am matching the word from the search text against First Name and Last Name as well as the reverse (Last Name & First Name)
I have used Replace function to remove any spaces between the charecters
This statement(in sql server)
SUBSTRING(name,CHARINDEX(' ',name),len(name)) + SUBSTRING(name,0,CHARINDEX(' ',name))
OR
in MY SQL
SUBSTRING(name,LOCATE(' ',name),LENGTH(name)) + SUBSTRING(name,0,LOCATE(' ',name))
is basically converting the First and LastName to LastName followed by First Name
Hope you got the concept and it may help you.