Skilled in SEO, content writing, and digital marketing. Completed several years of working in many organizations including multinational companies. I love to learn new things in life that keep me motivated.
Sure, you can do custom search in MySQL using the LIKE operator. The
LIKE operator allows you to search for a pattern in a column. The syntax is as follows:
SQL
SELECT *
FROM table_name
WHERE column_name LIKE pattern;
The pattern can be a regular expression or a simple string. For example, the following SQL statement will search for all rows in the
products table where the name column contains the word "product":
SQL
SELECT *
FROM products
WHERE name LIKE '%product%';
The % character is a wildcard that matches any number of characters. So, the
LIKE operator will match all rows where the name 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
CREATE TABLE products (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
price INT NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO products (name, price) VALUES
('Product 1', 100),
('Product 2', 200),
('Product 3', 300),
('Product 4', 400),
('Product 5', 500);
SELECT *
FROM products
WHERE name LIKE '%product%';
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.