The question is stated as there is a database on professors, departments, courses and schedules. Need to write a query that returns the names of all the professors and their respective courses. Each row must contain the name of the professor followed by the name of the course that the professor teaches. There must be no duplicates in terms of the rows.
The schema I have, in terms of the table name and the fields:
PROFESSOR: ID, NAME, DEPARTMENT_ID, SALARY
DEPARTMENT: ID, NAME
COURSE: ID, NAME, DEPARTMENT_ID, CREDITS
SCHEDULE: PROFESSOR_ID, COURSE_ID, SEMESTER, YEAR
The code I have right now:
SELECT DISTINCT p.Name AND c.NAME
FROM Prodessor p, Course c, Schedule S
WHERE
p.DEPARTMENT_ID = c.DEPARTMENT_ID
AND
p.ID = s.PROFESSOR_ID
AND
c.ID = c.COURSE_ID
The result I get is a list of all professors, but there aren't multiple courses, just a single one. What's going wrong here? It also mentioned that PROFESSOR.ID is foreign to COURSE.PROFESSOR_ID, so p.ID = s.PROFESSOR_ID is valid