Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mysql

I would like to get rows 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

How to solve this?

Thanks for reply

like image 942
Łukasz Zubrzycki Avatar asked Mar 18 '26 00:03

Łukasz Zubrzycki


1 Answers

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

SELECT * FROM `database-test`.users

Or

SELECT * FROM `database-test`.`users`
like image 60
Anant Kumar Singh Avatar answered Mar 19 '26 14:03

Anant Kumar Singh