MySQL Update Statement: Unknown 'table' in 'field list'

北慕城南 提交于 2019-12-11 15:27:07

问题


As soon as I am trying to use UPDATE, following error appears as soon as I hit GO:

1109 - Unkown table 'user' in 'field list'

Now since I knew that this table name is not the best and unique that has been used, I tried to get a little more specific with my statement:

UPDATE
    MyDatabase.user
SET
    MyDatabase.user.registeredAt = NOW()
WHERE
    MyDatabase.user.id = 3;

Still the same error. I tried it with a ` around the table or with the statement phpmyadmin builds for you on one button push but still the same. Since changing the name is not an option, even though I know it's bad, there is no other option than trying to get him find that table.

What am I missing?

Information about php and mySql:

  • PHP-Version: 5.6.38
  • Database-Client Version: libmysql - mysqlnd 5.0.11
  • Server-Version: 10.1.36-MariaDB

EDIT I have read about a bug when mySQL haven't been installed correctly, this error occurs more often. Since I've installed the whole package with XAMPP, there could be no possibility of this bug, isn't it?


回答1:


First, make sure you have a table named like that:

select * from information_schema.tables where table_schema = 'MyDatabase' and table_name = 'user';

`user´ is a reserved keyword, so you need to quote your table name with backticks.

UPDATE
    MyDatabase.`user`
SET
    MyDatabase.`user`.registeredAt = NOW()
WHERE
    MyDatabase.`user`.id = 3;

When your database name also needs quoting, do not include both database name and table name.

This is wrong:

`databasename.tablename`

This is right:

`databasename`.`tablename`


来源:https://stackoverflow.com/questions/52842026/mysql-update-statement-unknown-table-in-field-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!