这段代码有什么问题导致它吐回一个错误?
我的代码如下:
CREATE OR REPLACE VIEW vw_training AS
SELECT training.train_attended, clients.client_firstname, clients.client_lastname, clients.client_swn, clients.client_id, locations.loc_id, locations.loc_title, locationsp.loc_id, locationsp.loc_title,
FROM training
JOIN clients ON clients.client_id = training.train_clientid
JOIN locations AS locationsp ON locations.loc_id = training.train_pickup
LEFT JOIN locations ON locations.loc_id = clients.client_winz
这是我要返回的错误:
- 你的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 近 '来自培训加入客户 ON clients.client_id = training.train_clientid JOIN' 在第 3 行#1064
我正在运行 phpMyAdmin 版本 3.5.2.2.
我之前使用过具有不同值的脚本,没有任何问题。
FROM
子句前有一个额外的尾随逗号
SELECT ....,
locationsp.loc_id,
locationsp.loc_title, -- <<== remove this trailing comma
FROM training ...
和另一个会引发此消息的错误:
Unknown column 'locations.loc_id' in 'on clause'
是使用 tablename
而不是提供的别名。应该是,
JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
^^ should use alias here