0

What's wrong with this code that's making it spit back an error?

My code is as follows:

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

And this is the error I'm getting back:

#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

I'm running phpMyAdmin version 3.5.2.2.

I've used this script with different values before with no issues.

3
  • You have an extra comma at the end of the select list Commented Apr 23, 2013 at 1:56
  • Why downvoted? Legitimate question. Everybody makes mistakes. Upvoted. Commented Nov 5, 2017 at 10:46
  • This question can be closed as Typo/No Repro, since typo questions aren't likely to be useful for future readers. Commented Mar 20, 2023 at 9:55

1 Answer 1

1

You have an extra trailing comma before the FROM clause

SELECT ....,
       locationsp.loc_id, 
       locationsp.loc_title, -- <<== remove this trailing comma
FROM   training ...

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
Sign up to request clarification or add additional context in comments.

3 Comments

JOIN locations AS locationsp ON locations.loc_id = training.train_pickup is an error as well
@RichardTheKiwi right. it should be JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
@JW Thanks heaps! I can't believe I missed that. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.