LIKE Operator in SQL

The LIKE operator in SQL is used to search for a specified pattern in a column. It is particularly useful for string matching. The LIKE operator is often used with wildcard characters:

Simple Examples Using LIKEExample 1: Using % Wildcard.

SQL Syntax

SELECT first_name, last_name
FROM employees
WHERE first_name LIKE 'J%';         

In this example:

Example 2: Using _ Wildcard.

SQL Syntax

SELECT first_name, last_name
FROM employees
WHERE first_name LIKE '_a%';  

In this example:

The LIKE operator with the pattern '___' (three underscores) is used to match any string that is exactly three characters long. The underscore _ wildcard matches exactly one character. So, the query will return all employees whose first names are exactly three characters long.