为什么MySQL中的语法错误创建视图?

时间:2014-11-13 17:15:41

标签: mysql view

我一直在尝试在MySQL WorkBench中创建一个视图。虽然我想要使用的SELECT语句运行时没有任何问题,但是当我将其添加到VIEW时,我被告知我有语法错误但无法理解原因。我的脚本如下:

CREATE VIEW 
ClientMedical (LastName FirstName Highest) AS
SELECT Client.LastName, Client.FirstName, 
Qualifications.Highest FROM Client INNER JOIN Qualifications
ON Qualifications.idClient = Client.idClient  
ORDER BY Client.LastName DESC

3 个答案:

答案 0 :(得分:1)

您的列列表中缺少逗号:

CREATE VIEW 
ClientMedical (LastName, FirstName, Highest) AS -- Note the commas
SELECT     Client.LastName, Client.FirstName, Qualifications.Highest 
FROM       Client 
INNER JOIN Qualifications ON Qualifications.idClient = Client.idClient  
ORDER BY   Client.LastName DESC

答案 1 :(得分:0)

而不是:

CREATE VIEW 
ClientMedical (LastName FirstName Highest) AS
SELECT Client.LastName, Client.FirstName, 
Qualifications.Highest FROM Client INNER JOIN Qualifications
ON Qualifications.idClient = Client.idClient  
ORDER BY Client.LastName DESC

尝试:

CREATE VIEW ClientMedical AS
SELECT Client.LastName, Client.FirstName, 
Qualifications.Highest FROM Client INNER JOIN Qualifications
ON Qualifications.idClient = Client.idClient  
ORDER BY Client.LastName DESC;

答案 2 :(得分:0)

在过去一周的另一个项目之后,我扭转了局面 'ON Qualifications.idClient = Client.idClient' 到'ON Client.idClient = Qualifications.idClient' 它工作了!但为什么呢?