LIKE Keyword - Notes Lyst2976
LIKE Keyword - Notes Lyst2976
Scenario 1: Write a query to display first name and last name of the employee
whose first name starts with ‘AN’
Here we need to match first two characters as an after that any number of
characters means ‘an%’is the pattern matching
SELECT
first_name,last_name
FROM
employee
WHERE
first_name
LIKE 'an%';
Output:
first_name last_name
andy lumb
anjel nair
1
Scenario 2: Write a query to display the first name and last name of the
employee whose first name has the second character ‘o’.
Here we are matching for second character as o, so there should be any single
character before o(_o) and after o any number of characters so ‘_o%’ is the
pattern matching
SELECT
first_name,last_name
FROM
employee
WHERE
first_name
LIKE '_o%';
Output:
first_name last_name
tom taylor
rohan sharma
john king
Scenario 3: Write a query to display first name and last name of the employee
whose last name ends with ‘r’
2
Output:
first_name last_name
tom taylor
anjel nair
ram kumar
Scenario 4: Write a query to display first name and last name of the employee
whose last name contain substring ‘MA’
Output:
first_name last_name
ram kumar
rohan sharma
Scenario 5: Write a query to display first name and last name of the employee
whose first name begins with ‘r’ and at least 3 characters in length
Output
first_name last_name
ram kumar
3
rohan sharma
Scenario 6: Write a query to display first name and last name of the employee
whose first name begins contains ‘A’
SELECT
first_name, last_name
FROM
employee
WHERE
first_name
LIKE '%a%';
Output:
first_name last_name
andy lumb
anjel nair
ram kumar
rohan sharma
Scenario 7: Write a query to display first name and last name of the employee
whose last name has last third character ‘L’
SELECT
first_name,last_name
4
FROM
employee
WHERE
last_name LIKE '%l__';
Output:
first_name last_name
tom taylor
mike whalen
Scenario 8: Write a query to display first name and last name of the employee
whose last name has third character and last character ‘a’
SELECT
first_name,last_name
FROM
employee
WHERE
last_name LIKE '__a%a';
Output:
first_name last_name
rohan sharma
Scenario 9: Write a query to display first name and last name of the employee
whose first name has two consecutive ‘ll’
SELECT
first_name,last_name
5
FROM
employee
WHERE
first_name LIKE '%ll%';
Output:
first_name last_name
kelly davis
Scenario 10: Write a query to display first name and last name of the employee
whose first name is 5 characters long and has third character ‘h’
SELECT
first_name,last_name
FROM
employee
WHERE
first_name LIKE '__h__';
Output:
first_name last_name
rohan sharma
Scenario 11: Write a query to display first name and last name of the employee
whose last name consists of character ‘a’ twice in it
SELECT
6
first_name,last_name
FROM
employee
WHERE
last_name LIKE '%a%a%';
Output:
first_name last_name
rohan sharma
Scenario 12: Write a query to display first name, last name and salary of the
employee who are earning 6 digit salary
SELECT
first_name,last_name,salary
FROM
employee
WHERE
salary LIKE '______';
Output:
first_name last_name salary
Scenario 13: Write a query to display first name, last name and salary of the
employee whose salary starts with 4
7
SELECT
first_name,last_name,salary
FROM
employee
WHERE
salary LIKE '4%';
8
Output:
first_name last_name salary
Scenario 14: Write a query to display first name, last name and hire date of the
employee who are hired in the year 2018
SELECT first_name,last_name,hire_date
FROM employee
WHERE hire_date LIKE '2018%';
Output:
first_name last_name hire_date
Scenario 15: Write a query to display first name, last name and hire date of the
employee who are hired in the month of february
SELECT first_name,last_name,hire_date
FROM employee
WHERE hire_date LIKE '____-02%';
Output:
first_name last_name hire_date
9
john king 2021-02-09
Scenario 16: Write a query to display first name, last name and hire date of the
employee whose salary has last 3 digit as 0’s
SELECT
first_name,last_name,salary
FROM
employee
WHERE
salary LIKE '%000';
Output:
first_name last_name salary
10