繁体   English   中英

联接错误与多个表

[英]Joins are erroring with multiple tables

我正在尝试将多个表连接在一起,只获得一些字段

这是我的SQL代码:

SELECT t1.match_id, t1.provider_id, t1.visible, t2.match_type, t3.class_num, t3.location_id, t4.prov_name, t6.city_name
    FROM match AS t1 
        JOIN umtc_class AS t2
            on t1.match_id = t2.match_id
        JOIN abroad_class AS t3
            on t1.match_id = t3.match_id
        JOIN provider AS t4
            on t1.provider_id = t3.provider_id
        JOIN location AS t5
            on t3.location_id = t3.location_id
        JOIN location AS t6
            on t5.city_id = t6.city_id

1064-您的SQL语法有误; 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'match AS t1附近使用

    JOIN umtc_class AS t2
        on t1.match_id = t2.match_id

'在第2行

我一直在弄乱它,但是我什么也没办法。...任何想法都说明为什么它不起作用?

FROM match AS t1 
    JOIN umtc_class AS t2
        on t1.match_id = t2.match_id
    JOIN abroad_class AS t3
        on t1.match_id = t3.match_id
    JOIN provider AS t4
        on t1.provider_id = t3.provider_id   --<-- This ON clause should have t4 in it
    JOIN location AS t5
        on t3.location_id = t3.location_id   --<-- This ON clause should have t5 in it
    JOIN location AS t6
        on t5.city_id = t6.city_id

任何ON子句都应定义表名或表联接中已跟随的表名与先前的结果集之间的关系。

MATCH是函数名称,因此是保留字。 尝试使用标准名称的表名和数据库名称作为前缀:

SELECT ...
FROM mydb.match AS t1
SELECT t1.match_id, t1.provider_id, t1.visible, t2.match_type, t3.class_num, t3.location_id, t4.prov_name, t6.city_name
    FROM match AS t1 
        JOIN umtc_class AS t2
            on t1.match_id = t2.match_id
        JOIN abroad_class AS t3
            on t1.match_id = t3.match_id
        JOIN provider AS t4
            on t1.provider_id = t4.provider_id  //here was mistake
        JOIN location AS t5
            on t3.location_id = t5.location_id //here was mistake
        JOIN location AS t6
            on t5.city_id = t6.city_id

而不是使用match尝试使用[match],即在[和]之间包含匹配

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM