MySQL UPDATE没有正确更新

时间:2014-01-20 13:46:01

标签: mysql

我有一个UPDATE查询,如下所示:

UPDATE orders 
SET 
    order_status = 1,
    amount_remaining = 0.00000000
WHERE
    market_pair_id = 2 AND user_id = 1
        AND sale_rate = 0.00000001
        AND sale_amount = 100.00000000
        AND order_type = 1 LIMIT 1

以下是来自phpmyadmin的数据快照:

http://cl.ly/image/3m3M2f2R3R3Z/Screen%20Shot%202014-01-20%20at%2012.55.03.png

我的查询显然有3个匹配的行,但是没有更新的消息受到0行的影响。有人可以了解正在发生的事情吗?

一些补充信息:我无法通过主键更新,因为我没有它,我的目标只是更新我的数据的许多匹配行中的一个。

非常感谢

2 个答案:

答案 0 :(得分:0)

从查询末尾删除LIMIT 1并尝试

UPDATE orders 
    SET 
        order_status = 1,
        amount_remaining = 0.00000000
    WHERE
        market_pair_id = 2 AND user_id = 1
            AND sale_rate = 0.00000001
            AND sale_amount = 100.00000000
            AND order_type = 1 

答案 1 :(得分:0)

.try this

 UPDATE orders 
 SET 
    order_status = 1,
    amount_remaining = 0.00000000
 WHERE order_id IN (
     SELECT order_id FROM (
         SELECT order_id FROM orders 
          WHERE market_pair_id = 2 
          AND user_id = 1
          AND sale_rate = 0.00000001
          AND sale_amount = 100.00000000
          AND order_type = 1  
         LIMIT 1
     ) tmp
 );