Looking for separate words in the same string in MySQL

0

My question is relatively simple, but I could not find an answer that really helped:

My user searches for a name on a form: Fulano Silva

The record in my bank is like So-and-so of Tal Silva

SELECT * FROM 'dados' WHERE 'nome' LIKE '%".Fulano Silva."%'

When doing the search with PHP in MySQL by Fulano Silva using LIKE he will not be able to find the record!

If he had searched only for Fulano or just for Silva , he would find it, but for having more strings between Fulano and Silva is not found.

How can I resolve this situation? Should I separate the strings in the sentence and search for them individually? How could he do that? Thank you!

    
asked by anonymous 16.03.2017 / 18:29

1 answer

-1

Place % among all the words to be filtered:

SELECT * FROM 'dados' WHERE 'nome' LIKE '%".Fulano%Silva."%'

I've put an example in SQLFiddle to see it working.

    
16.03.2017 / 18:31