gpt4 book ai didi

php - 多表 JOIN 抛出 'Not unique table/alias' 错误

转载 作者:行者123 更新时间:2023-11-29 13:53:43 24 4
gpt4 key购买 nike

以下查询会引发错误:

SELECT * FROM proposal_data
INNER JOIN proposal_data
ON proposal_data_second.proposal_id = proposal_data.proposal_id

INNER JOIN proposal_data_second
ON proposal_data_third.proposal_id = proposal_data_second.proposal_id
INNER JOIN proposal_data_third
ON proposal_data_fourth.proposal_id = proposal_data_third.proposal_id

错误是:

#1066 - Not unique table/alias: 'proposal_data'

我做错了什么?

最佳答案

您错误地连接了表。

在当前查询中,您在声明之前连接表:

例如取前三行

SELECT * FROM proposal_data
INNER JOIN proposal_data
ON proposal_data_second.proposal_id = proposal_data.proposal_id

在声明 proposal_data_second 表之前,您需要将 proposal_dataproposal_data_second 连接起来。

此外,您不需要使用表名 peoposal_data 两次:

SELECT * FROM proposal_data
INNER JOIN proposal_data --This is invalid syntax

试试这个:

SELECT * FROM proposal_data
INNER JOIN proposal_data_second
ON proposal_data_second.proposal_id = proposal_data.proposal_id
INNER JOIN proposal_data_third
ON proposal_data_third.proposal_id = proposal_data_second.proposal_id
INNER JOIN proposal_data_fourth
ON proposal_data_fourth.proposal_id = proposal_data_third.proposal_id

更多信息请参见MySQL: JOIN Syntax

关于php - 多表 JOIN 抛出 'Not unique table/alias' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16249323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com