我想在一个中运行以下两个查询:
SELECT id FROM user_settings WHERE ......
$id = id_from_query_above();
$value = 100; // this could be anything
INSERT INTO user_config (sid, value) VALUES($id, $value) ON DUPLICATE KEY UPDATE value=$value
(请注意,如果已经插入了与主键相关联的行,我想更新。)
答案 0 :(得分:1)
您需要insert . . . select
语法:
INSERT INTO user_config(sid, value)
SELECT id, $value
FROM user_settings
WHERE ......
ON DUPLICATE KEY UPDATE value = $value;