简体   繁体   English

语法错误或访问冲突:1066 不是唯一的表/别名:'tasks'

[英]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.您不需要在FROMJOIN子句中都列出表。 You just need to reorder the JOIN clauses, because a JOIN can only refer to tables in previous JOIN or FROM clauses.您只需要重新排序JOIN子句,因为JOIN只能引用先前JOINFROM子句中的表。

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.

相关问题 Laravel-语法错误或访问冲突:1066不是唯一的表/别名: - Laravel - Syntax error or access violation: 1066 Not unique table/alias: Laravel-语法错误或访问冲突:1066不是唯一的表/别名 - Laravel - Syntax error or access violation: 1066 Not unique table/alias 为什么我会收到此错误? 语法错误或访问冲突:1066不唯一的表/别名:'Employees' - Why do I get this error? Syntax error or access violation: 1066 Not unique table/alias: 'Employees' SQLSTATE [42000]:语法错误或访问冲突:1066在laravel中不是唯一的表/别名 - SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias in laravel SQLSTATE [42000]:语法错误或访问冲突:1066 - SQLSTATE[42000]: Syntax error or access violation: 1066 Codeignitor 错误号:1066“不是唯一的表/别名” - Codeignitor Error Number: 1066 "Not unique table/alias" Laravel:1066不是唯一的表/别名 - Laravel: 1066 Not unique table/alias 错误:不是唯一的表/别名:'companies'数据库(错误):1066 - Error: Not unique table/alias: 'companies' Database (error): 1066 为什么错误#1066-不是唯一的表/别名:“ cat_rapoarte” - Why error #1066 - Not unique table/alias: 'cat_rapoarte' 错误号码:1066不唯一的表/别名:codeigniter中的'tb_perumahan' - Error Number: 1066 Not unique table/alias: 'tb_perumahan' in codeigniter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM