2017-03-10 104 views
0

我需要一些關於MySQL服務器代碼的幫助。我不斷收到此錯誤:帶有SQL代碼的錯誤消息

未能執行SQL:SQL

SELECT 
    CONCAT(INSTRUCTOR.FIRST_NAME, INSTRUCTOR.LAST_NAME) AS INSTRUCTOR_NAME, 
FROM 
    INSTRUCTOR 
LEFT JOIN 
    APPROVED_INSTRUCTOR 
    ON INSTRUCTOR.INSTRUCTOR_ID=APPROVED_INSTRUCTOR.INSTRUCTOR_ID 

UNION 

SELECT 
    CONCAT(INSTRUCTOR.FIRST_NAME, INSTRUCTOR.LAST_NAME) AS INSTRUCTOR_NAME, 
FROM 
    INSTRUCTOR 
RIGHT JOIN 
    APPROVED_INSTRUCTOR 
    ON INSTRUCTOR.INSTRUCTOR_ID=APPROVED_INSTRUCTOR.Instructor_ID; 

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 INSTRUCTOR LEFT JOIN APPROVED_INSTRUCTOR ON INSTRUCTOR.INSTRUCTOR_ID=APPROV' at line 1

我有雙重檢查表和字段名稱和有關的研究,但一切我讀一個小時做表明沒有代碼存在問題。

+2

任何你用SQL Server和MySQL標記的理由嗎? – DavidG

回答

2

INSTRUCTOR_NAME兩次出現後刪除逗號:

此:

SELECT CONCAT(INSTRUCTOR.FIRST_NAME, INSTRUCTOR.LAST_NAME) AS INSTRUCTOR_NAME, 

應該是:

SELECT CONCAT(INSTRUCTOR.FIRST_NAME, INSTRUCTOR.LAST_NAME) AS INSTRUCTOR_NAME 
1

你不需要SELECTFROM語句之間用逗號。

SELECT 
    CONCAT(INSTRUCTOR.FIRST_NAME, INSTRUCTOR.LAST_NAME) AS INSTRUCTOR_NAME 
FROM 
    INSTRUCTOR 
LEFT JOIN 
    APPROVED_INSTRUCTOR 
    ON INSTRUCTOR.INSTRUCTOR_ID=APPROVED_INSTRUCTOR.INSTRUCTOR_ID 

UNION 

SELECT 
    CONCAT(INSTRUCTOR.FIRST_NAME, INSTRUCTOR.LAST_NAME) AS INSTRUCTOR_NAME 
FROM 
    INSTRUCTOR 
RIGHT JOIN 
    APPROVED_INSTRUCTOR 
    ON INSTRUCTOR.INSTRUCTOR_ID=APPROVED_INSTRUCTOR.Instructor_ID;