Question: Filter with the LIKE Operator
Understand how to use the SQL LIKE operator to filter data effectively by writing queries that extract student records ending with certain characters. This lesson focuses on applying pattern matching in SQL to analyze student performance data.
We'll cover the following...
Question
Given the following StudentGrades table structure:
StudentGrades
RecordID | StudentID | StudentName | Subject | Marks |
1 | st-101 | Alexa | Mathematics | 90.00 |
2 | st-101 | Alexa | Science | NULL |
3 | st-102 | Diana | Mathematics | 80.00 |
4 | st-102 | Diana | Science | 88.00 |
5 | st-103 | Carl | Mathematics | NULL |
6 | st-103 | Carl | Science | 92.00 |
7 | st-104 | Sara | Mathematics | 75.00 |
8 | st-104 | Sara | Science | 85.00 |
9 | st-105 | Karen | Mathematics | 85.00 |
10 | st-105 | Karen | Science | 90.00 |
Additional information
You are provided with a table named StudentGrades that contains the following columns:
RecordID: A column of unique values. It’s the primary key of this table.StudentID: Unique identifier for each student.StudentName: The name of the student.Subject: The subject for which the grade is recorded.Marks: The marks obtained by the student in the corresponding subject.
You are required to analyze student performance data. The StudentGrades table holds important details like ID and name along with the marks of the students obtained in Science and Mathematics. Here’s a task for you: Can you write a query using SQL LIKE to find out the records of students whose name ends with “a”?
Let’s see if you can find the answer!
Expected output
The expected output is shown below:
RecordID | StudentID | StudentName | Subject | Marks |
1 | st-101 | Alexa | Mathematics | 90.00 |
2 | st-101 | Alexa | Science | NULL |
3 | st-102 | Diana | Mathematics | 80.00 |
4 | st-102 | Diana | Science | 88.00 |
7 | st-104 | Sara | Mathematics | 75.00 |
8 | st-104 | Sara | Science | 85.00 |
Try it yourself
You can try to write a query in the following playground:
Hints
Below are some hints to help you understand these concepts better: