Pattern matching in SQL- Like Operator

by lochan2014 | Apr 7, 2024 | SQL | 0 comments

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”.

Written By

undefined

Related Posts

Submit a Comment

Your email address will not be published. Required fields are marked *