In MySQL, the LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
It is particularly useful when we want to perform pattern matching with wildcard characters.
SELECT columns FROM table_name WHERE column_name LIKE pattern;
columns: The columns we want to retrieve from the table.
table_name: The name of the table from which we want to retrieve data.
column_name: The column we want to search.
pattern: The pattern to search for, which can include wildcard characters.
%: Represents zero or more characters.
_: Represents a single character.
SELECT * FROM products WHERE product_name LIKE 'Lap%';
This query retrieves all columns from the "products" table where the "product_name" starts with "Lap".
This query retrieves the maximum price from the "products" table and aliases the result as "max_price_product".
SELECT * FROM customers WHERE name LIKE '% Smith';
This query retrieves all columns from the customers table where the name ends with "Smith".
SELECT * FROM products WHERE NOT product_name LIKE '%Table%';
Note: This query retrieves all columns from the "products" table where the "product_name" does not contain "Table".