INSERT INTO orders_total SET `title`='Discount Coupon:', `text` = '-$40.00', `value` = '40.00' WHERE `orders_id` = '15474' AND `class`='ot_coupon
它给出了以下mysql错误:
#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 'WHERE `orders_id` = '15474' AND `class`='ot_coupon'' at line 1
知道我做错了吗?
答案 0 :(得分:4)
INSERT
语句用于插入新行,现在更新现有行,因此WHERE
子句在INSERT
中无效。您打算UPDATE
。
UPDATE orders_total
SET
`title`='Discount Coupon:',
`text` = '-$40.00',
`value` = '40.00'
WHERE
`orders_id` = '15474'
AND `class`='ot_coupon'
如果这是一个插入而不是更新,它就不能依赖orders_id = 15474
之类的条件。如果要插入新行,则还需要插入这些值。
INSERT INTO orders_total (`orders_id`, `class`, `title`, `text`, `value`) VALUES (15474, 'ot_coupon', 'Discount Coupon:', '-$40.00', '40.00');