Back to basics - SQL Wild Cards
It's funny how the simplest of things could actually fool you. If you want to search for a particular String, let's say "Lamia", but you don't know if that name actually has some trailing numbers or something. You just know that it starts with "Lam". How do you search for this in SQL? I had this as a question in one interview and because maybe I had very little exposure to this keyword, I ended up using the regexp keyword in MySQL when the answer was just a simple WHERE username LIKE "me".
While working on a feature for my current project, I was searching for a username. So as an example, I use the username "Lamia" but don't know that it really is Lamia. I just know that it starts with "Lam". I tried the following
SELECT * FROM users_tbl WHERE username LIKE "Lam"
It didn't work. I approached my team lead (quite an intelligent person) and he told me to put a "%" in the end of the string.
SELECT * FROM users_tbl WHERE username LIKE "Lam%"
Now, I swear I knew what the "%" symbol mean. But I really couldn't remember so I searched w3schools. Okay, so the percent symbol is used as some sort of wildcard. I couldn't hate myself more! But again, this proves me wrong that I learn nothing in my current job. Lolz!