dotancohen
dotancohen

Reputation: 31511

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!

Upvotes: 0

Views: 665

Answers (1)

rrehbein
rrehbein

Reputation: 4170

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();

Upvotes: 6

Related Questions