Learn SQL Server

SQL LIKE Operator

The LIKE operator is used to list all rows in a table whose column values match a specified pattern. It is useful when you want to search rows to match a specific pattern, or when you do not know the entire value. For this purpose we use a wildcard character ‘%’.

For example: To select all the students whose name begins with ‘S’

SELECT first_name, last_name
FROM student_details
WHERE first_name LIKE ‘S%’;

The output would be similar to:

first_name          last_name
————-          ————-
Stephen                 Fleming
Shekar                   Gowda

The above select statement searches for all the rows where the first letter of the column first_name is ‘S’ and rest of the letters in the name can be any character.