CBSE Class 12 Computer Science
Question 73 of 91
Grouping Records, Joins in SQL — Question 8
Back to all questions 8
Question Table EXAM_RESULTS
| STU ID | FNAME | LNAME | EXAM ID | EXAM_SCORE |
|---|---|---|---|---|
| 10 | LAURA | LYNCH | 1 | 90 |
| 10 | LAURA | LYNCH | 2 | 85 |
| 11 | GRACE | BROWN | 1 | 78 |
| 11 | GRACE | BROWN | 2 | 72 |
| 12 | JAY | JACKSON | 1 | 95 |
| 12 | JAY | JACKSON | 2 | 92 |
| 13 | WILLIAM | BISHOP | 1 | 70 |
| 13 | WILLIAM | BISHOP | 2 | 100 |
| 14 | CHARLES | PRADA | 2 | 85 |
What SQL statement do we use to print out the record of all students whose last name starts with 'L'?
- SELECT * FROM EXAM_RESULTS WHERE LNAME LIKE 'L%' ;
- SELECT * FROM EXAM_RESULTS WHERE LNAME LIKE 'L';
- SELECT * FROM EXAM_RESULTS WHERE LNAME 'L';
- SELECT * FROM EXAM_RESULTS WHERE LNAME <> 'L';
SELECT * FROM EXAM_RESULTS WHERE LNAME LIKE 'L%' ;+--------+-------+-------+---------+------------+
| stu_id | fname | lname | exam_id | exam_score |
+--------+-------+-------+---------+------------+
| 10 | LAURA | LYNCH | 1 | 90 |
| 10 | LAURA | LYNCH | 2 | 85 |
+--------+-------+-------+---------+------------+
SELECT * FROM EXAM_RESULTS WHERE LNAME LIKE 'L%';— The LIKE operator is used for pattern matching in SQL. '%' is a wildcard character that matches zero or more characters. 'L%' specifies that the last name (LNAME) should start with 'L' followed by zero or more characters. TheSELECT *statement retrieves all columns from the EXAM_RESULTS table for the matching records.SELECT * FROM EXAM_RESULTS WHERE LNAME LIKE 'L';— This query attempts to select all columns (*) from the EXAM_RESULTS table where the last name (LNAME) is exactly equal to 'L'. However, when using the LIKE operator in SQL for pattern matching, we use wildcard characters (%) to represent unknown parts of a string.SELECT * FROM EXAM_RESULTS WHERE LNAME 'L';— This statement contains a syntax error. In SQL, when using the WHERE clause to filter records based on a specific condition, we need to use comparison operators or functions to define the condition properly.SELECT * FROM EXAM_RESULTS WHERE LNAME <> 'L';— This query retrieves records where the last name is not equal to 'L'. It does not specifically look for last names starting with 'L', so it's not the correct option for the given requirement.