Link to home
Start Free TrialLog in
Avatar of sue Tons
sue Tons

asked on

How can I turn my code to an update?

I would like to update every unitcode which is not in the sk_units_temp_table but in those two tables
   unitboundary and unitheader showing  terminated = 'True'   and set the terminated to  'Flase'.

Here is my code below:
   
   SELECT *
             FROM   unitboundary
                    join unitheader USING (unitcode)
             WHERE  terminated = 'False'
               AND  unitcode IN (SELECT unit_code
                                 FROM   sk_units_temp_table)
                    AND province = 'SK'
                    AND ( unitcode, highdesc ) NOT IN (SELECT unit_code, highdesc
                                                       FROM sk_units_temp_table);
Avatar of Sean Stuber
Sean Stuber

is terminated in both unitboundary and unitheader?  If not, which table needs updated?
If in both, does it matter if one is true and the other false? Do you still update both?
Do you update only the one, or do you not do either because they don't match?

Also, which of the other columns belong to each table?

I'm not sure what you're trying to show with your sample query.

Does province factor into this?  Your written description does not suggest so, but you've included it in your example query.
Similarly, highdesc is it supposed to be a factor?

 If unitcode is not in the sk_unit_temp_table, then obviously it won't be in the table when combined with another column.
Your written description is confusing on this point as well, because your example specifically looks for unitcode that IS in the sk_units_temp_table but your description says you are looking for unitcode that is NOT in the table.


Perhaps some sample input data and expected results would help
Avatar of sue Tons

ASKER

Unitcode is in both tables but Terminated is only in Unitheader Table.  It's all based on unitcode, like if unitcode in Boundary and Unitheader tables are not in sk_units_temp_table then update the terminated  column in unitheader = True where unitcode not in sk_units_temp_table  that's what I am trying to do.  Sorry about my example.  

Can we use this query please?

SELECT *
             FROM   unitboundary
                    join unitheader USING (unitcode)
             WHERE  unitcode NOT IN (SELECT unit_code
                                 FROM   sk_units_temp_table)
                    AND province = 'SK';
I still don't know where province comes from.

Also, is there a foreign key relationship between unitboundary and unitcode?  That is, is it possible for a unitcode in unitboundary to not be in unitheader or the other way around?
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You nailed it, Thank you so very much.