We've expanded our news coverage and improved our search! Visit
oreilly.com for the latest or search for all things across O'Reilly!
Article:
 |
|
MySQL Crash Course, Part 3
|
Subject: |
|
Updating fields using contraints |
Date: |
|
2004-08-10 17:33:53 |
From: |
|
Ireece
|
|
OrgTable
OrganizationId IndividualId IndividualName Sum_Points
1 1 Kate
1 2 Ashley
1 3 Don
2 10 Mary
PointsTable
OrganizationId Sum_Points
1 50
2 3
Run an update statement, so the first line for an organization will have the the Sum_Points field updated
Result set should look like this
OrganizationId IndividualId IndividualName Sum_Points
1 1 Kate 50
1 2 Ashley
1 3 Don
2 10 Mary 3
This normal update statement will go in and update each line in the Sum_Points field where the OrganizationId matches
Do you know what contraint I can use so I can update the Sum_Points field w/o duplication
I know I can create a cursor to make the updates but I'm trying to avoid that
update OrgTable
set Sum_Points= p.Sum_Points
from OrgTable o
join PointsTable p
on o.OrganizationId = p.OrganizationId
|