我试图将多个表连接在一起,只获得一些字段
这是我的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
JOIN umtc_class AS t2
on t1.match_id = t2.match_id
'在第2行
我一直在搞乱它,但我无法到达任何地方......任何想法都解释为什么它不起作用?
答案 0 :(得分:3)
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
子句都应该定义表名所遵循的表名与表或表的连接之前的结果集之间的关系。
答案 1 :(得分:1)
MATCH是一个函数名,因此是一个保留字。尝试使用前置数据库名称的完全限定表名:
SELECT ...
FROM mydb.match AS t1
答案 2 :(得分:0)
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
答案 3 :(得分:0)
而不是使用匹配尝试使用[匹配],即封闭[和]
之间的匹配