简体   繁体   中英

Joins are erroring with multiple tables

I'm trying to join multiple tables together and only get some of the fields

here's my sql code:

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 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match AS t1

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

' at line 2

I keep messing around with it but I can't get anywhere....any ideas has to why it isn't working?

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

Any ON clause should define the relation between the table name is has followed and preceding result set from a table or joins of tables.

MATCH is a function name and thus a reserved word. Try using the fully qualified table name with the database name prepended:

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],即在[和]之间包含匹配

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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