LIKE operator is used in the WHERE clause to filter results by pattern matching. LIKE operator uses 2 wildcard options. ‘%’ sign to match any number of characters(0,1, or more) and ‘_’ to match exactly 1 character.
LIKE '%abc%abc%'; LIKE '_abc';
Consider an employee table as shown below:
Below is the SQL query to identify employees with invalid email addresses: The logic used here is if the ’email’ value does not contain ‘@’ it is considered invalid.
SELECT * FROM employee WHERE email not like '%@%';
Below is the SQL query to identify all employees with their first names starting with ‘a’
SELECT * FROM employee WHERE first_name like 'a%';
Below is the SQL query to identify all employees that have second character as ‘o’ in their first name.
SELECT * FROM employee WHERE first_name like '_o%';