Context
I'm creating a comment system where users can use the "@" symbol to mention other users' usernames. I want to be able to go into the database and search through the comments table so that comments that include "@_____" (insert username) are given. However, it should only contain that username in the word; if there's a username randomusername
and I search for randomusername
in the query, I don't want names like randomusernameextended
to show up because part of its string is what I queried. Additionally, there should be able to be more than just the username in the result, which is why using WHERE comment = "@____"
doesn't work; it only returns rows that ONLY include that username. I want to return rows that simply contain the username in the message (example: "@____ random comment here" is returned when I query the username).
Question
How do I search a mySQL table for a specific row, one that includes the specific string I searched for but can also contain more text?
Things I Have Tried
I have already tried using the %LIKE%
operator to return results that include the username string. The problem is that I only want the username to be in the one word I return and nothing more, but given the nature of the operator, I can't search for the username randomusername
without getting randomusernameextended
, as I mentioned.
Let me know if there is any confusion. Thanks.