1

我想在选择表后更新 a 列

SELECT id_copies, id_shop, id_dvd 
FROM dvd_copies
WHERE id_dvd = '001-192.168.1.103-6' AND id_shop='002'
ORDER BY id_copies DESC
LIMIT 2;

我只有 2 行要更新,我该如何更新这些行?

4

2 回答 2

3

您可以在更新查询中使用嵌套选择,注意它会用相同的值更新您的行,而不是每行的不同值

UPDATE dvd_copies 
SET your_column_to_update ='your value'
WHERE id_copies IN(
    SELECT t.id_copies FROM 
    (SELECT id_copies
        FROM dvd_copies 
        WHERE id_dvd = '001-192.168.1.103-6' AND id_toko='002'
        ORDER BY id_copies DESC LIMIT 2
    ) t
)
于 2014-03-31T07:49:07.883 回答
3

您还可以执行以下操作:

UPDATE dvd_copies
SET your_column_to_update ='your value'
WHERE id_dvd = '001-192.168.1.103-6' AND id_toko='002'
ORDER BY id_copies DESC
LIMIT 2
于 2014-03-31T08:20:27.157 回答