How to update column with data from other tables?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mimime
    New Member
    • Sep 2007
    • 5

    How to update column with data from other tables?

    Scenario:
    Assign a new_customer_id to each existing customer of our three business. A master lookup table (M) was given to me with pre-populated (SEQ_NOs), (NEW_CUSTIDs), and NULL in (OLD_CUSTIDS). My duty is to

    (1) Fill the M.OLD_CUSTID column with existing customer ids from T1, T2, T3 (uniquely).
    (2) Once the master lookup table is filled, add (SEQ_NO), and (NEW_CUSTID) column to the 3 existing customer tables to hold the new information.
    (3) At the end of the project, remove the existing customer ids from the T1, T2, T3.

    Question
    Since there are no associations (keys) between the master table and the existing customer tables. The M.OLD_CUSTID and T1.NEW_CUSTID are NULL at this stage, I don't know how to complete the following code:

    update M
    set OLD_CUSTID= (select OLD_CUSTID from T1 where M.??=T1.??)

    Can someone help me ASAP? Thanks in Advance.
    -ORACLE Newbi
  • Dave44
    New Member
    • Feb 2007
    • 153

    #2
    there has to be some way of relating the old cust id to the new ones (eg name field), some other column or something. Otherwise you are just guessing. what other columns are there?

    Comment

    • mimime
      New Member
      • Sep 2007
      • 5

      #3
      Originally posted by Dave44
      there has to be some way of relating the old cust id to the new ones (eg name field), some other column or something. Otherwise you are just guessing. what other columns are there?
      This is exactly my problem - I am building a "MASTER LOOKUP TABLE", the only columns in this table are (SEQUENCE_ID), (NEW_CUSTOMER_I D), and (OLD_CUSTOMER_I D).

      Once the M table is ready, the NEW_CUSTOMER_ID will be the primary key, the application can use this table to track the business activities done under the (old customer id).

      We have about 8000 customers.

      TIA

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        It will be very difficult to guess how to update that without any related fields between the tables. You might need to update all those manually.

        But that is not a good option.

        Comment

        • subashsavji
          New Member
          • Jan 2008
          • 93

          #5
          Originally posted by mimime
          Scenario:
          Assign a new_customer_id to each existing customer of our three business. A master lookup table (M) was given to me with pre-populated (SEQ_NOs), (NEW_CUSTIDs), and NULL in (OLD_CUSTIDS). My duty is to

          (1) Fill the M.OLD_CUSTID column with existing customer ids from T1, T2, T3 (uniquely).
          (2) Once the master lookup table is filled, add (SEQ_NO), and (NEW_CUSTID) column to the 3 existing customer tables to hold the new information.
          (3) At the end of the project, remove the existing customer ids from the T1, T2, T3.

          Question
          Since there are no associations (keys) between the master table and the existing customer tables. The M.OLD_CUSTID and T1.NEW_CUSTID are NULL at this stage, I don't know how to complete the following code:

          update M
          set OLD_CUSTID= (select OLD_CUSTID from T1 where M.??=T1.??)

          Can someone help me ASAP? Thanks in Advance.
          -ORACLE Newbi
          This may helpful to you
          [code=oracle]

          UPDATE employees e
          SET department_name =
          (SELECT department_name
          FROM departments d
          WHERE e.department_id = d.department_id );
          //
          UPDATE employees
          SET salary = (SELECT employees.salar y + rewards.pay_rai se
          FROM rewards
          WHERE employee_id =
          employees.emplo yee_id
          AND payraise_date =
          (SELECT MAX(payraise_da te)
          FROM rewards
          WHERE
          employee_id = employees.emplo yee_id))
          WHERE employees.emplo yee_id
          IN (SELECT employee_id FROM rewards);
          //

          [/code]

          Comment

          Working...