Given a column named fullname, how can I filter on firstname/lastname with no order ?
In the example below in javascript, the query is not valid when searching by lastname
function getQuery(searchWord){
return `SELECT * FROM user WHERE fullname like '%${searchWord}%' `
}
// trying to search fullname "Elon Musk"
getQuery("Elon M") // okay
getQuery("Musk E") // no result
What is the query that allow me to find "Elon Musk" by searching by keyword "Musk Elon" ?
NB: columns firstname and lastname exists as well
2
Answers
Finally i resolved the problem by using some javascript.
You can do a
FULLTEXT
search usingMATCH
AGAINST
:And you have to create a
FULLTEXT search index
on the columnfullname
Or you can split your
searchWord
by space and doLIKE '%$(searchWordPart1)%' AND LIKE '%$(searchWordPart2)%'
etc.