0

I have (3) tables: Professor, Comment, Course

I'm trying to get a few columns to display the professor with all the courses and all the comments they have.

My tables enter image description here

comment

enter image description here

SQL:

  SELECT prefix, code, info, date
        FROM Course, Comment
        JOIN Professor ON Professor.pID = Comment.pID
        AND JOIN Course ON Course.cID = Comment.cID
        WHERE Comment.pID = ?

Throws error: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN Course ON Course.cID = Comment.cID WHERE Comment.pID = '273'' at line 4

3 Answers 3

2
SELECT prefix, code, info, date
    FROM Comment
    JOIN Professor ON Professor.pID = Comment.pID
    JOIN Course ON Course.cID = Comment.cID
    WHERE Comment.pID = ?

Just remove the AND before the second JOIN and remove Course in the From list. You may need to change the order of the tables depending on what table data you are primarily after.

Advise that you have a read through the MySQL JOIN syntax page.

Sign up to request clarification or add additional context in comments.

2 Comments

Now it throws error: Syntax error or access violation: 1066 Not unique table/alias: 'Course'' in
Fixed. Remove the Course table in the From part.
0

change 'AND JOIN' to just 'JOIN'

Comments

0

There is no AND JOIN. Please read about JOIN syntax in the manual before attempting to use it.

Additionally, you reference table Course twice.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.