[英]Syntax error or access violation: 1066 Not unique table/alias: 'tasks'
I keep getting this error, and found only answers to users of laravel..我不断收到此错误,并且只找到了 laravel 用户的答案。
I have this query:我有这个查询:
$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");
and I've been trying to debug but I can't find out what the issue is... any suggestion please?我一直在尝试调试,但我无法找出问题所在……请问有什么建议吗? Thanks!
谢谢!
You don't need to list tables in both the FROM
and JOIN
clauses.您不需要在
FROM
和JOIN
子句中都列出表。 You just need to reorder the JOIN
clauses, because a JOIN
can only refer to tables in previous JOIN
or FROM
clauses.您只需要重新排序
JOIN
子句,因为JOIN
只能引用先前JOIN
或FROM
子句中的表。
You also have a ;
你也有一个
;
in the middle of the query, at the end of the JOIN tasks
line.在查询的中间,在
JOIN tasks
行的末尾。 Everything after that is not part of the query, and this will cause an error becauase PDO doesn't allow multiple queries in one call.之后的所有内容都不是查询的一部分,这将导致错误,因为 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.