Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update from Sub-query
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01519023
Message ID:
01519055
Views:
23
>>
>>
>>Update TableA Set Field1 = ST.Sum_TOT
>>FROM TableA INNER JOIN (select sum(FldA+FldB) as Sum_Tot from TableB group b y FldC) ST
>>ON TableA.FieldC = ST.FieldC
>
>A follow up question, if I may, please. The above SQL Update will update only those records in table TableA that have child records in TableB, correct? So if I wanted to update ALL records in TableA, would it be correct to change JOIN with LEFT JOIN then? And then to do NVL(ST.SUM_TOT,0) instead of just ST.SUM?

Yes, you should change INNER TO LEFT JOIN.
A few typos here:
Update TableA Set Field1 = ST.Sum_TOT
FROM TableA
INNER JOIN (select FieldC, /* Here, you should include FieldC in the query*/ sum(FldA+FldB) as Sum_Tot
                   from TableB 
           group by /*Here b y must be BY and FldC must be FieldC*/ FieldC) ST
ON TableA.FieldC = ST.FieldC
:-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform