Most popular course
Easysqljoingroup bysubquery
Return the title of the course (or courses, on a tie) with the most enrollments, sorted by title. Courses without enrollments don't count. With no enrollments at all, return nothing.
Tables
- courses (id INTEGER, title TEXT)
- enrollments (student_id INTEGER, course_id INTEGER)
Example 1
courses
| id | title |
|---|---|
| 1 | JavaScript |
| 2 | Python |
| 3 | SQL |
enrollments
| student_id | course_id |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 1 |
| 5 | 2 |
Expected result
| title |
|---|
| JavaScript |
Constraints
- 0 ≤ rows ≤ 1000
- The order of rows matters
Submit checks your solution against 7 tests, including hidden ones.
SQL
-- Write one SELECT query. Tables: courses, enrollments SELECT