|
Posted by Norman Peelman on 12/05/07 19:46
Mikhail Kovalev wrote:
> On 5 Des, 18:42, Norman Peelman <npeel...@cfl.rr.com> wrote:
<snipped>
>> INSERT INTO nodes (node_address, node_count) VALUES ($node_address,
>> $node_count) ON DUPLICATE KEY UPDATE node_count=node_count+1
>>
>> ...will INSERT new entries and UPDATE existing entries in one swoop.
>>
>> Norm
>
> Ok, suppose I'm joining to structures which have been created
> separately,
> from before i have ('112/225/930', 3)
> and i want to add ('112/225/930', 2), which also happens to be present
> in the second table, only with a different count,
> to make ('112/225/930', 5)
>
> From there I want to make it the general case so that when updating an
> entry with count 1 I am actually adding ('112/225/930', 1) to the
> existing one, if it exists:
>
> INSERT INTO nodes (node_address, node_count) VALUES (<new_address>,
> <new_count>) ON DUPLICATE KEY UPDATE node_count = node_count +
> <new_count>
>
> Is this correct? (Do I have to use <> in VALUES, I'm following an
> example which does it?)
No replace everything '<..>' with your own variable name, that will do it.
$new_count = 5
....ON DUPLICATE KEY UPDATE node_count = $new_count
Not sure what you mean by 'second table'. How many do you have? Though
this was one table...
Norm
[Back to original message]
|