Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Write SQL Join With Left Join

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Write SQL Join With Left Join. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

CarGurus Learning uses student and course records to track internal technical training. Write a PostgreSQL query that lists every student and any course enrollment associated with that student.

Requirements

  1. Return every row from students, including students with no enrollment.
  2. Include the student ID and name, plus the enrollment's course ID, course code, and course title.
  3. Use LEFT JOIN so students without a matching enrollment remain in the result with NULL course columns.
  4. Order the output by student_id, then course_id.

Schema

students
ColumnTypeDescription
student_idPKINTEGERUnique student identifier
student_nameVARCHAR(100)Student's full name
enrollments
ColumnTypeDescription
enrollment_idPKINTEGERUnique enrollment identifier
student_idINTEGERReferences students.student_id
course_idINTEGERReferences courses.course_id
courses
ColumnTypeDescription
course_idPKINTEGERUnique course identifier
course_codeVARCHAR(20)Short course code
course_titleVARCHAR(150)Course title
Tablesstudentsenrollmentscourses
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results