Search code examples
mysqlwhere-clausenavicat

Why i need to define table name everytime in WHERE clause?


i was testing a software on my computer , i have a mysql installed on it . now i have transfered this software to a server . no any mysql command is working

for example this is the command that was working on my computer

SELECT COUNT(*) FROM camera WHERE stored=3;

when i try to execute it on my server here is the result

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 'stored=3' at line 1

but this one is working

SELECT COUNT(*) FROM camera WHERE camera.stored=3;

is there any way to restore it without needing to define the table name ?


Solution

  • Stored is a MySQL Reserved Word, so MySQL thinks you are intending to use that Reserved Word.

    When you qualify it with the Table Name, then it knows what you are talking about.

    UPDATE: You could wrap stored in back ticks (shown below) so it's treated as text and not a Reserved Word.

    SELECT COUNT(*) FROM camera WHERE `stored`=3;