LIKE Operator:
The LIKE operator is used to search for a specified pattern in a column.
It allows the use of wildcards:
% (percent sign): Matches zero or more characters.
_ (underscore): Matches any single character.
Examples:
SELECT * FROM employees WHERE last_name LIKE 'Sm%': Finds employees with last names starting with “Sm”.
SELECT * FROM products WHERE product_name LIKE '%chair%': Finds products with names containing “chair” anywhere.
Case Insensitivity:
SQL pattern matching is case-sensitive by default, but you can use functions or modifiers to perform case-insensitive matching.
Example (MySQL):
SELECT * FROM employees WHERE last_name LIKE 'smith' COLLATE utf8_general_ci: Performs case-insensitive matching for last names equal to “smith”.
Leave a Reply