I need to use the LIKE keyword or some other similar operator for this purpose:
In the database, the name and surname is stored as one column and it’s in the order surname name (e.g. “Doe John”).
I have a search bar with lets you enter your name and surname. When I am going to search, I require that if you enter name surname instead of surname name (e.g. if you enter “John Doe”), I still want the same results to show up as if you had written surname name.
How can I achieve this?
If your table is
MyISAM, you can create aFULLTEXTindex on both fields:and issue this query:
This will return both
John DoeandDoe John.On a
MyISAMtable this query will work even without creating the index, however, in this case it will be much more slow.Update:
This will work even if you have name and surname in a single field:
Update 2:
On an
InnoDBtable, you can use regular expressions: