2011-04-17 81 views
0

我与follwoing字段一个MySQL表更新MySQL表:在上述顺序我运行follwoing误差与滤波器

update match1 set weight = 5 where desc = 'fat' and id != '6'; 

follwoing

id, desc, value, people, amount, weight 

是错误消息我得到:

**#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 'desc = 'bat' and id = 6' at line 1 

有人可以请让我知道这是怎么回事?

+0

确定你运行相同的查询,错误是'desc ='bat'和id = 6',代码中是desc ='fat'和id!='6' ? – 2011-04-17 08:14:28

回答

1

desc是mysql中的关键字。使用反引号,即

where `desc` = 'fat' 
+0

以及我有一个疑问:1.当我跑更新match1设置重量= 5其中id = 4;它甚至没有提供任何错误,即使id是关键字。 – whatf 2011-04-17 08:01:57

+0

我必须同意Andrian - 在这种特殊情况下,'DESC'确实会引发问题,因为它是MySQL中的一个关键字......无论如何,在查询语句中反向引用列是很好的做法,这会让您的语句更加干净,并且让您的机会更少的错误。 – Laimoncijus 2011-04-17 08:13:04

+0

id不是关键字! – 2011-04-17 08:14:37