Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating from multiple tables

Status
Not open for further replies.

Rozza

Technical User
Jul 25, 2002
67
GB
Hi,
I've got a query which totals a customers spending from the transactions table and then updates a field in the client table with the total value previously calculated.
The query looks like this:

update CLIENT c1
SET c1.field_1 = (select sum(tr.credit) from CLIENT c2 inner join
transactions tr on (c2.toro_clientid = tr.toro_clientid)
WHERE c2.toro_clientid = c1.toro_clientid)

The only problem is that when you run the query it takes in excess of 25 minutes to complete. I am running the query on the local server so there's no network involved. There is approx 12000 records in the client table and 6000 in the transactions table. There is an index on the fields making up the join.
I have to run this query on 65 different imported data sets so you can see why I need to speed this up!!
Why does this run so slowly?


Any help would be GREEEAATLY appreciated!!!!

Cheers

Paul
 
Try this query:

update CLIENT SET field_1 = (select sum(credit) from transactions tr WHERE CLIENT.toro_clientid = tr.toro_clientid)

If I understand your question well it will give the same result (I hope :)).

Otto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top