37.5k views
4 votes
Which query returns all student names with the highest grade?

a) SELECT name FROM students WHERE grade = MAX(grade)
b) SELECT name FROM students WHERE grade = HIGHEST(grade)
c) SELECT name FROM students WHERE grade = (SELECT MAX(grade) FROM students)
d) SELECT name FROM students ORDER BY grade DESC LIMIT 1

User Edaklij
by
7.6k points

1 Answer

2 votes

Final answer:

The correct query for returning all student names with the highest grade is option c), which uses a subquery to find the maximum grade first and then fetches the names matching that grade.

Step-by-step explanation:

The query that returns all student names with the highest grade is the one that uses a subquery to select the maximum grade first, and then matches this grade in the outer query. The correct option is:

c) SELECT name FROM students WHERE grade = (SELECT MAX(grade) FROM students)

This query first finds the highest grade by using the MAX() function in the subquery (SELECT MAX(grade) FROM students), and then matches this result in the outer WHERE clause to return all names of students with this highest grade. Option d) is not correct because it only returns one name, even if multiple students share the highest grade.

User Tere
by
8.0k points