MYSQL - Having trouble with query involving multiple tables

时间:2015-10-30 22:10:13

标签: mysql

I need help writing a query to find the name of students who are enrolled in a course taught by a professor who wrote an article called "X"

I have the code to find the professor who wrote the article, but I'm having trouble joining tables to find the names of students enrolled in a course taught by that prof.

SELECT first_name, last_name, title)
FROM intellectual_contributions as ic, ic_contributors as icc, stakeholders as s
WHERE title ="X"
and ic.ic_id=icc.ic_id
and icc.stakeholder_id=s.stakeholder_id

1 个答案:

答案 0 :(得分:2)

You need some more INNER JOIN's. Also, try to use JOINed syntax.

SELECT aa.first_name, aa.last_name, cc.title
FROM stakeholders AS aa
INNER JOIN ic_contributors AS bb
ON aa.stakeholder_id = bb.stakeholder_id
INNER JOIN intellectual_contributions AS cc
ON bb.ic_id = cc.ic_id
INNER JOIN course_enrollments AS dd
ON aa.stakeholder_id = dd.stakeholder_id
WHERE cc.title = "X";