How to do custom search in MySQL?
How to do custom search in MySQL?
102
27-Jul-2023
Aryan Kumar
28-Jul-2023Sure, you can do custom search in MySQL using the
LIKE
operator. TheLIKE
operator allows you to search for a pattern in a column. The syntax is as follows:SQL
The
pattern
can be a regular expression or a simple string. For example, the following SQL statement will search for all rows in theproducts
table where thename
column contains the word "product":SQL
The
%
character is a wildcard that matches any number of characters. So, theLIKE
operator will match all rows where thename
column contains the word "product", regardless of whether the word is at the beginning, end, or middle of the column.Here is an example of how to do custom search in MySQL:
SQL
This will return the following result:
As you can see, the
LIKE
operator has matched all rows where thename
column contains the word "product".Here are some additional things to keep in mind when using the
LIKE
operator:LIKE
operator is case-insensitive by default.ESCAPE
keyword to escape special characters, such as the%
character.BINARY
keyword to make theLIKE
operator case-sensitive.