There can be some scenarios where you need to pull all the records from the database where the values of a particular column starts or ends with a specific character. To solve cases like these, there is a special character known as percentile “%” which is being used.
Let us take a look at data first and then we will cover few cases:
Query:
SELECT * FROM Employee;
Output:
Problem 1: Write a SQL query to get all the employees whose name start with “J”
Query:
SELECT * FROM Employee
WHERE name Like 'j%';
Output:
Problem 2: Write a SQL query to get all the employees whose name end with “n”
Query:
SELECT * FROM Employee
WHERE name Like '%n';
Output:
Problem 3: Write a SQL query to get all the employees whose name start with “J” and end with “e”
Query:
SELECT * FROM Employee
WHERE name Like 'j%E';
Output:
Point to Remember:
String matching is case insensitive. All of these search terms “j%E”, “J%E”, “J%e”, “j%e” will behave exactly the same.
We collect cookies and may share with 3rd party vendors for analytics, advertising and to enhance your experience. You can read more about our cookie policy by clicking on the 'Learn More' Button. By Clicking 'Accept', you agree to use our cookie technology.
Our Privacy policy can be found by clicking here