Additional question to MySQL: Insert data into table, some data comes from another table (relational)
My question above basically asked "how can I insert a row into a table, using information found in another row". The answer was to use a query such as:
INSERT INTO user_config(cid, sid, value)
SELECT $cid, id, $value
FROM user_settings
WHERE mid='$mid' AND name='$name'
ON DUPLICATE KEY UPDATE value = $value;
My problem now is, I need to insert multiple rows. For each row I need to insert, there is a different value for $cid
, $value
, $mid
and $name
. For example I could run the following (pseudo):
function x($cid, $mid, $name, $value){
// run query:
INSERT INTO user_config(cid, sid, value)
SELECT $cid, id, $value
FROM user_settings
WHERE mid='$mid' AND name='$name'
ON DUPLICATE KEY UPDATE value = $value;
}
x(1,'a','b');
x(2,'c','d');
x(3,'f','e');
Problem is, that would run 3 queries, and I want to be able to do this in one. Is it possible? I could provide an array for $cid
, $mid
and $name
if that helps the problem?