我有这个SELECT语句:
SELECT * FROM `all_uu_features`
INNER JOIN `all_video_names`
ON `all_video_names`.`video_id` = `all_uu_features`.`video_id`
WHERE `language` = 'en'
AND `navigation` = 'laser-interface'
我需要反转这个并更新数据库。我怎么做?有没有更好的方式:
UPDATE `all_uu_features` SET ...
WHERE `language` = 'en'
AND `navigation` = 'laser-interface'
和
UPDATE `all_video_names' SET ...
WHERE video_id = ?
这可以用一个陈述来完成吗?
all_video_names:
video_id | video_name
-------------------
1 | ABC
2 | DEF
3 ....
all_uu_features:
feature_name | video_id | language | navigation
-----------------------------------------------
Hello 1 | 1 | en | laser-interface
Hello 2 | 2 | fr | laser-interface
答案 0 :(得分:1)
MySQL中有一个多表更新语法。实际上,您可以在几乎完全正在尝试的文档中找到一个示例。
-- docs example
UPDATE TABLE_1 LEFT JOIN TABLE_2 ON TABLE_1.COLUMN_1= TABLE_2.COLUMN_2
SET TABLE_1.COLUMN = EXPR WHERE TABLE_2.COLUMN2 IS NULL
在你的情况下,它将是:
UPDATE
`all_uu_features` uu
INNER JOIN `all_video_names` vid
ON uu.`video_id` = vid.`video_id`
SET uu.column_name = 1, vid.column_name = 2
WHERE `language` = 'en'
AND `navigation` = 'laser-interface';