为什么这个SQL命令不起作用

时间:2011-03-27 21:30:02

标签: sql

SELECT info, date
FROM Professor, Professor_Comment, Comment
WHERE pID = ?
AND Professor_Comment.pcID = Professor.pcID
AND Comment.commID = Professor_Comment.commID;
;

sql of 3 tables

2 个答案:

答案 0 :(得分:5)

这可能是因为pID含糊不清而Professor没有pcID

试试这个:

SELECT info, date
FROM Professor_Comment, Comment
WHERE pID = ?
AND Comment.commID = Professor_Comment.commID;

但是,我更喜欢显式的JOIN语法:

SELECT info, date
FROM Professor_Comment
JOIN Comment ON Comment.commID = Professor_Comment.commID
WHERE pID = ?;

答案 1 :(得分:0)

  1. 您有pID = ?,但pID不明确,因为它显示在ProfessorProfessor_Comment

    将唯一的pID更改为Professor.pIDProfessor_Comment.pID

  2. 您有Professor_Comment.pcID = Professor.pcID,教授表将其列为dID,而不是pcID