开发者

MySQL insists that field does not exist, then tells me that it does exist

CentOS 4 or 5, with 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>

I did enter the someField and 开发者_运维问答userTable into the SELECT statement by mouse-copy/pasting in the terminal, so I know that it is not a typo issue. What could be the issue here?

Thanks!


The tick marks are used for quoting columns and table names. With the dot in the quotes, it is not seeing that as a divider between the parts. Add a couple extra tick marks to correct it.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜