架构创建失败:不是唯一的表/别名:' tbl

时间:2015-01-25 17:16:12

标签: php sql left-join

![有关此错误的任何帮助?我应该更改别名的哪个表名?] [1]

                    SELECT
                            C1.answer1 AS answer1,
                            C2.answer2 AS answer2,
                            C3.answer3 AS answer3,
                            C4.answer4 AS answer4,
                            C5.answer5 AS answer5,
                            C6.answer6 AS answer6,
                            C7.answer7 AS answer7,
                            C8.answer8 AS answer8,
                            C9.answer9 AS answer9,
                            C10.answer10 AS answer10
                            FROM tblprelimanswer A
                            LEFT JOIN tblprelimstudentans a1
                            ON A.answer1 = a1.answer1
                            LEFT JOIN tbl
                            ON A.answer2 = a1.answer2
                            LEFT JOIN tbl
                            ON A.answer3 = a1.answer3
                            LEFT JOIN tbl
                            ON A.answer4 = a1.answer4
                            LEFT JOIN tbl
                            ON A.answer5 = a1.answer5
                            LEFT JOIN tbl
                            ON A.answer6 = a1.answer6
                            LEFT JOIN tbl
                            ON A.answer7 = a1.answer7
                            LEFT JOIN tbl
                            ON A.answer8 = a1.answer8
                            LEFT JOIN tbl
                            ON A.answer9 = a1.answer9
                            LEFT JOIN tbl
                            ON A.answer10 = a1.answer10

我的表格更改别名是否正确?哪些是要纠正的? 纠正我的错误。帮我摆脱这个。请...谢谢!

2 个答案:

答案 0 :(得分:0)

您多次加入tbl而没有别名。如果您多次加入同一个表,则每次需要为其添加一个唯一的别名。

可能是LEFT JOIN而不是额外的ON,您只需要AND中的其他条件,在这种情况下,您可以使用LEFT JOIN tblprelimstudentans a1 ON A.answer1 = a1.answer1 AND A.answer2 = a1.answer2 AND A.answer3 = a1.answer3 AND A.answer4 = a1.answer4 AND A.answer5 = a1.answer5 AND A.answer6 = a1.answer6 AND A.answer7 = a1.answer7 AND A.answer8 = a1.answer8 AND A.answer9 = a1.answer9 AND A.answer10 = a1.answer10

{{1}}

我不确定你在这里打算做什么,但看起来你可能正在使用糟糕的设计。如果您发布样本数据/架构和期望的结果,人们将能够找到问题的根源,而不仅仅是语法问题。

答案 1 :(得分:0)

据推测,您希望from子句定义C别名。我猜它会是这样的:

                        FROM tblprelimanswer A
                        LEFT JOIN tblprelimstudentans a1
                        ON A.answer1 = a1.answer1
                        LEFT JOIN tbl c1
                        ON c1.answer2 = a1.answer2
                        LEFT JOIN tbl c2
                        ON c2.answer3 = a1.answer3
                        LEFT JOIN tbl c3
                        . . .