Professors Teaching Outside Their Department
Updated
Problem statement
A university stores its departments, its professors (each belongs to one department) and its courses (each belongs to one department and is taught by one professor).
Find every course that a professor teaches outside their own department. For each such course, return the professor's name as professor_name, the course name as course_name, and the name of the course's department as course_department.
Return the rows in any order.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
departments
| Column | Type | Nullable | Description |
|---|---|---|---|
| department_idPK | Integer | No | — |
| name | Text | No | — |
professors
| Column | Type | Nullable | Description |
|---|---|---|---|
| professor_idPK | Integer | No | — |
| name | Text | No | — |
| department_id | Integer | No | — |
Foreign key: department_id → departments(department_id)
courses
| Column | Type | Nullable | Description |
|---|---|---|---|
| course_idPK | Integer | No | — |
| name | Text | No | — |
| department_id | Integer | No | — |
| professor_id | Integer | No | — |
Foreign key: department_id → departments(department_id)
Foreign key: professor_id → professors(professor_id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| professor_name | Text | No | — |
| course_name | Text | No | — |
| course_department | Text | No | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
- For this exercise, assume 1 to 100 departments, 1 to 1000 professors and 0 to 10000 courses.
- All IDs are positive integers, unique within their table.
- Every professor and course references an existing department, and every course references an existing professor.
- Names are nonempty strings of at most 100 characters and need not be unique.
More Patreon interview questions
Similar questions at other companies
- Build Taxi Driver Performance FeaturesBoston Consulting Group · OABoston Consulting Group interview questions
- Students Scoring Above AverageCapstone Investment Advisors · OA
- Bond Interest Summary Above 3%Wells Fargo · OAWells Fargo interview questions
- Employee Promotion OpportunitiesIntuit · OAIntuit interview questions
- Students and Their SubjectsBirla Pivot · OA
- Companies with Average Salary Above 40000AT&T · OAAT&T interview questions
- Weekend Appointments for Consular Services ReschedulingMcKinsey & Company · OAMcKinsey & Company interview questions
- Companies Above a Salary ThresholdVerisk · OA
- Customer Resource Usage AnalysisIBM · OAIBM interview questions
- Customers Who Never OrderedAccenture · OAAccenture interview questions