The name column contains items like 'John Smith', 'Elsa John Sanders', 'LilJohn Thomson', 'John'. How can I structure a query just to return the names with John but not LilJohn.
I cannot do a LIKE '%John%' as it would return 'LilJohn Thomson'.
Looks like this is the same as: Search for "whole word match" in MySQL
The approach uses a slick regular expression.
You can use REGEXP function.
Try this:
SELECT *
FROM tableA a
WHERE a.name REGEXP '[[:<:]]John[[:>:]]'