MySQL坚持认为该字段不存在,然后告诉我它确实存在

时间:2011-09-09 21:18:53

标签: mysql sql join sql-update

CentOS 4或5,使用MySQL 5.0.77:

mysql> UPDATE
   ->  `userTable`
   -> INNER JOIN `anotherTable`
   ->   ON `userTable.userid`=`anotherTable.userid`
   -> SET `userTable.someField`="Jimmy Page"
   -> WHERE `userTable.someField`="Jim Morrison"
   ->   AND `anotherTable.date` < NOW();
ERROR 1054 (42S22): Unknown column 'userTable.someField' in 'field list'
mysql>
mysql> SELECT count(someField) FROM userTable;
+---------------+
| count(someField) |
+---------------+
|          5076 |
+---------------+
1 row in set (0.00 sec)

mysql>

我确实通过终端中的鼠标复制/粘贴将someField和userTable输入SELECT语句,所以我知道这不是拼写错误。这可能是什么问题?

谢谢!

1 个答案:

答案 0 :(得分:6)

刻度线用于引用列和表名。使用引号中的点,它不会将其视为部件之间的分隔符。添加几个额外的刻度标记来纠正它。

 UPDATE
  `userTable`
 INNER JOIN `anotherTable`
   ON `userTable`.`userid`=`anotherTable`.`userid`
 SET `userTable`.`someField`="Jimmy Page"
 WHERE `userTable`.`someField`="Jim Morrison"
   AND `anotherTable`.`date` < NOW();