
Join the Conversation!
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.
Sometimes we need to loosely match some filters in our Database. Think of a search. What if we wanted our website to contain a searchbar that let's users look for other users by 'name'?
Well we can use , but then the user needs to have the exact name for the results to work.
SQL instead let's us loosely match things using "LIKE".
"LIKE" gives us the wildcard operator so that we can match the search string anywhere in the results. The beginning, the end, or the middle.
To match just the beginning of a value- we append the symbol to the end of our search term.
SELECT * FROM Users
WHERE name LIKE "Mar%";
In this example we searched for meaning that we'll match any names that start with and have anything after. So we'll match values like Marcus, Mario, and Marshal.
To match the end of a value- we preprend the symbol to the beginning of our search term.
SELECT * FROM Users
WHERE name LIKE "%ar";
In this example we searched for meaning we'll match any named that end in , no matter what is at the beginning of the name.
If we instead want to match anything in the middle of a value- we can surround our search term with symbols:
SELECT * FROM Users
WHERE name LIKE "%ar%";
This will match any rows with a name that contains anywhere in the name. Oscar, Mario, Lars, Marcus all will match.
You'll often use for searching loosely over values.
"Please login to view comments"
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.