#1064-创建视图时,SQL语法有错误 [英] #1064 - You have an error in your SQL syntax when creating a View
问题描述
有人可以告诉我这段代码出了什么问题吗?
Could someone please tell me what's wrong with this code that's making it spit back an error?
我的代码如下:
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
这是我回来的错误:
#1064
-您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 在'FROM培训附近,在客户端上加入客户端.client_id= training.train_clientid加入第3行
#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 'FROM training JOIN clients ON clients.client_id = training.train_clientid JOIN' at line 3
我正在运行phpmyadmin版本信息:3.5.2.2
I'm running phpmyadmin Version information: 3.5.2.2
我之前将此脚本使用了不同的值
I've used this script with different values before with no issues
推荐答案
在FROM
子句之前您还有一个逗号结尾
You have an extra trailing comma before the FROM
clause
SELECT ....,
locationsp.loc_id,
locationsp.loc_title, -- <<== remove this trailing comma
FROM training ...
和另一个将引发此消息的错误:Unknown column 'locations.loc_id' in 'on clause'
是使用tablename
而不是提供的别名.应该是
and another error that will raise this message: Unknown column 'locations.loc_id' in 'on clause'
is the use of tablename
and not the alias supplied. it should be,
JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
^^ should use alias here
这篇关于#1064-创建视图时,SQL语法有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!