SQL LIKE

www.i‮ig‬ftidea.com

SQL LIKE is a operator used in the WHERE clause of a SELECT statement to search for a specific pattern in a column.

The LIKE operator is often used with the wildcard characters % (percent sign) and _ (underscore) to match a pattern.

The percent sign % represents any number of characters, including none. For example, the following statement retrieves all employees whose first names start with "J":

SELECT * FROM employees WHERE first_name LIKE 'J%';

The underscore _ represents a single character. For example, the following statement retrieves all employees whose first names have five letters, where the third letter is "a":

SELECT * FROM employees WHERE first_name LIKE '__a__';

You can also combine the wildcard characters with literal characters to search for specific patterns. For example, the following statement retrieves all employees whose last names end with "son":

SELECT * FROM employees WHERE last_name LIKE '%son';

The LIKE operator is case-insensitive, meaning that it treats uppercase and lowercase letters as the same. If you want to perform a case-sensitive search, you can use the COLLATE clause. For example:

SELECT * FROM employees WHERE last_name COLLATE Latin1_General_CS_AS LIKE '%SON';

This statement performs a case-sensitive search for all employees whose last names end with "SON".