Łukasz Zubrzycki Łukasz Zubrzycki - 2 months ago 7
MySQL Question

MySQL SELECT record from database.table (database name contain '-')

I would like get row from another database so I created query:

SELECT * FROM database-test.users

MySQL result that error:

Database_Exception [ 42000 ]: SQLSTATE[42000]: Syntax error or access violation: 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 '-test.users' at line 1

Thanks for reply

Answer Source

You need to do it like below (use back-ticks around table name):-

SELECT * FROM `database-test`.users


SELECT * FROM `database-test`.`users`