If I search for LENA, I only want to get results where LENA is one word and not part of a word like Lenason or Anna-Lena or Malena
How do I write such a query, not
"select * from users where name like '%LENA%'"
What should it be instead?
If I search for LENA, I only want to get results where LENA is one word and not part of a word like Lenason or Anna-Lena or Malena
How do I write such a query, not
"select * from users where name like '%LENA%'"
What should it be instead?
You could use REGEXP
:
SELECT fields
FROM users
WHERE name REGEXP '(^|\s+)LENA($|\s+)'
You might be better off looking into Full Text Search for this.
Otherwise I think you're stuck doing something like this
"select * from users WHERE CONCAT(' ',name, ' ') like '% LENA %'"
Which will be pretty inefficient as it requires a full table scan.