更新sql中的两列

时间:2013-08-19 18:33:24

标签: mysql sql-update

这是我需要更改的数据表。

SELECT appId, categoryID, categoryName, classdesc
FROM apps JOIN appsCategories USING(appID)
JOIN categories USING (categoryID)
JOIN classes USING (classID)
WHERE classDesc = "Auto"

返回如下内容:

appid         categoryID         categoryName        classDesc

400           100                Public              AUTO
405           101                Business            AUTO
410           102                Auto                AUTO
415           102                Auto                AUTO

我想更新我的表,以便下面的所有数据都更新为categoryName为Auto,categoryID为102.我需要以某种方式使用上面的Select语句,但我不确定如何更新这两列。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

假设您只想为表中的每一行更新这两列,这应该可以。

UPDATE apps a
JOIN appsCategories b
    ON a.appID = b.appID             //Whatever your keys are
JOIN categories c
    ON b.categoryID = c.categoryID   //Whatever your keys are
JOIN classes d
    ON c.classID = d.classID         //Whatever your keys are
SET categoryID='102', categoryName='Auto'
WHERE classDesc = "Auto"