[SQL] How do I optimize this?

2009-03-17 Thread Wei Weng
Hi all. I have the following scenario: A table T (int t1; int t2; ... int t10; int tkey) A table D (int da; int db), And I have the following query update T set t1 = b.aa FROM (select COUNT(1) as aa FROM D WHERE D.da = ) as b where tkey = ; update T set t2 = b.aa FROM (select COUNT(1) as aa FR

Re: [SQL] How do I optimize this?

2009-03-17 Thread Wei Weng
I made a mistake in the queries: They should be update T set t1 = b.aa FROM (select COUNT(1) as aa FROM D WHERE D.da = 1) as b where tkey = ; update T set t2 = b.aa FROM (select COUNT(1) as aa FROM D WHERE D.da = 2) as b where tkey = ; ... update T set t10 = b.aa FROM (select COUNT(1) as aa F

Re: [SQL] How do I optimize this?

2009-03-18 Thread Richard Huxton
Wei Weng wrote: > I made a mistake in the queries: > > They should be > > update T set t1 = b.aa FROM (select COUNT(1) as aa FROM D WHERE D.da = > 1) as b where tkey = ; > update T set t2 = b.aa FROM (select COUNT(1) as aa FROM D WHERE D.da = > 2) as b where tkey = ; > ... > update T set t10 = b.