使用 order by 和 limit-mysql 在单个查询中更新两个不同 table 的两列

Update two columns of two different table in single query with order by and limit-mysql

查询

 UPDATE vcd_resorts AS resorts, 
           vcd_deals AS deals 
    SET    resorts.rst_live_date = Date_add(Curdate(), INTERVAL 4 day), 
           deals.del_date = Date_add(Curdate(), INTERVAL 4 day) 
    WHERE  0 = (SELECT resort_id_count 
                FROM   (SELECT Count(rst_id) AS resort_id_count 
                        FROM   vcd_resorts 
                        WHERE  rst_supersaver_resort = 1 
                               AND rst_live_date BETWEEN Curdate() + 1 AND 
                                                         Curdate() + 4) 
                       temp) 
           AND resorts.rst_supersaver_resort = 1 
           AND resorts.rst_id = deals.del_resort_id 
           AND deals.del_supersaver_deal = 1 
    ORDER BY resorts.rst_live_date ASC 
    LIMIT 1

错误

#1221 - Incorrect usage of UPDATE and ORDER BY

这个和任何其他方法有什么问题

Update中使用ORDER BY毫无意义。因为无论顺序如何,命令都会更新所有匹配的订单。

使用不带 ORDER BY 子句的更新命令如下:

 UPDATE vcd_resorts AS resorts, 
           vcd_deals AS deals 
    SET    resorts.rst_live_date = Date_add(Curdate(), INTERVAL 4 day), 
           deals.del_date = Date_add(Curdate(), INTERVAL 4 day) 
    WHERE  0 = (SELECT resort_id_count 
                FROM   (SELECT Count(rst_id) AS resort_id_count 
                        FROM   vcd_resorts 
                        WHERE  rst_supersaver_resort = 1 
                               AND rst_live_date BETWEEN Curdate() + 1 AND 
                                                         Curdate() + 4) 
                       temp) 
           AND resorts.rst_supersaver_resort = 1 
           AND resorts.rst_id = deals.del_resort_id 
           AND deals.del_supersaver_deal = 1 
    LIMIT 1

我得到了这个问题的答案

UPDATE vcd_resorts AS resorts, 
                vcd_deals AS deals 
                SET    resorts.rst_live_date = Date_add(Curdate(), INTERVAL 4 day), 
                       deals.del_date = Date_add(Curdate(), INTERVAL 4 day) 
                WHERE  0 = (SELECT resort_id_count 
                            FROM   (SELECT Count(rst_id) AS resort_id_count 
                                    FROM   vcd_resorts 
                                    WHERE  rst_supersaver_resort = 1 
                                           AND rst_live_date BETWEEN Curdate() + 1 AND 
                                                                     Curdate() + 4) 
                                   temp) 
                AND resorts.rst_supersaver_resort = 1 
                AND resorts.rst_id = deals.del_resort_id 
                AND deals.del_supersaver_deal = 1 
                AND resorts.rst_id = (SELECT resort_id 
                                    FROM   (SELECT rst_id AS resort_id 
                                             FROM   vcd_resorts 
                                             WHERE  rst_supersaver_resort = 1 
                                             ORDER  BY rst_live_date ASC 
                                             LIMIT  1) temp1)

我已经放置了一个条件,它取代了 order by 和 limit