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%';
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Sure, you can do custom search in MySQL using the
LIKEoperator. TheLIKEoperator allows you to search for a pattern in a column. The syntax is as follows:SQL
The
patterncan be a regular expression or a simple string. For example, the following SQL statement will search for all rows in theproductstable where thenamecolumn contains the word "product":SQL
The
%character is a wildcard that matches any number of characters. So, theLIKEoperator will match all rows where thenamecolumn 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
LIKEoperator has matched all rows where thenamecolumn contains the word "product".Here are some additional things to keep in mind when using the
LIKEoperator:LIKEoperator is case-insensitive by default.ESCAPEkeyword to escape special characters, such as the%character.BINARYkeyword to make theLIKEoperator case-sensitive.