我一直收到此错误,并只找到laravel用户的答案。
我有这个查询:
$stmt = $pdo->query("SELECT branches.branch_id, branches.branch_name,
tasks.task_name, tasks.task_status, tasks.real_amount,
tasks.task_start, tasks.task_finish, tasks.description, projects.proj_name, projects.project_id
FROM retail2.branches, retail2.projects, retail2.tasks
JOIN tasks ON tasks.branch_id = branches.branch_id;
JOIN branches_projects ON projects.project_id = branches_projects.proj_id
JOIN branches ON branches.branch_id = branches_projects.branch_id");
并且我一直在尝试调试,但是我找不到问题所在……有什么建议吗?谢谢!
答案 0 :(得分:1)
您无需同时在FROM
和JOIN
子句中列出表。您只需要对JOIN
子句重新排序,因为JOIN
只能引用先前JOIN
或FROM
子句中的表。
在查询中间,;
行的结尾处还有一个JOIN tasks
。之后的所有内容都不是查询的一部分,这将导致错误,因为PDO不允许在一个调用中进行多个查询。
SELECT branches.branch_id, branches.branch_name,
tasks.task_name, tasks.task_status, tasks.real_amount,
tasks.task_start, tasks.task_finish, tasks.description, projects.proj_name, projects.project_id
FROM projects
JOIN branches_projects ON projects.project_id = branches_projects.proj_id
JOIN branches ON branches.branch_id = branches_projects.branch_id
JOIN tasks ON tasks.branch_id = branches.branch_id;