1

I like Sequel Pro to handle MySQL databases on Mac. Now I'm triying to create a view with this:

CREATE VIEW '_view_userlist' AS 
SELECT u.userid,u.fullname,u.username,e.userid,e.listid,e.title,e.status 
FROM users u 
LEFT OUTER JOIN list e ON e.userid=u.userid 
WHERE u.status=1 AND e.status=1 
ORDER BY e.title ASC

But I get this error:

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 ''_view_userlist' AS 
SELECT u.userid,u.fullname,u.username,e.userid,e.listid,e.t' at line 1

I'm no sure what really means. When a I try the request without the CREATE VIEW line all goes smooth.

I have MySQL 5.5.35. Any help o advise ??

junihh
  • 502
  • 1
  • 9
  • 25
  • Identifiers (the name of the view) must not be enclosed in single quotes. Single quotes are used to specify string literals. –  Apr 27 '14 at 16:59

2 Answers2

4

change

CREATE VIEW '_view_userlist' AS 

as

CREATE VIEW `_view_userlist` AS 

or

CREATE VIEW _view_userlist AS 

DEMO

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
2

You should quote view name so the right syntax is

CREATE VIEW _view_userlist AS SELECT u.userid, ...

Also check the manual page http://dev.mysql.com/doc/refman/5.5/en/create-view.html

Eugeniy Petrov
  • 101
  • 1
  • 3
  • 6