Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Oracle query

Options
  • 10-07-2014 2:25pm
    #1
    Registered Users Posts: 1,830 ✭✭✭


    The aim is to create a generic query is to update the Target table with the values from the Loading table by referencing the Shelf to Store Assignment Table.
    E.g In the first record, update value1 from 10 to 50 etc. Can this be done in a single query?

    Loading Table
    PROD_ID STORE_ID VALUE1 VALUE2
    1 1100 50 75
    2 1200 60 80

    Target Table
    PROD_ID SHELF_ID VALUE1 VALUE2
    1 33 10 15
    2 35 20 30

    Shelf to Store Assignment Table
    STORE_ID SHELF_ID
    1100 33
    1200 35


Comments

  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    The aim is to create a generic query is to update the Target table with the values from the Loading table by referencing the Shelf to Store Assignment Table.
    E.g In the first record, update value1 from 10 to 50 etc. Can this be done in a single query?

    Loading Table
    PROD_ID STORE_ID VALUE1 VALUE2
    1 1100 50 75
    2 1200 60 80

    Target Table
    PROD_ID SHELF_ID VALUE1 VALUE2
    1 33 10 15
    2 35 20 30

    Shelf to Store Assignment Table
    STORE_ID SHELF_ID
    1100 33
    1200 35

    Can you give a better idea of what you expect, both before and after?

    Also take a look at triggers.


  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    Sorry, struggling to get my head around this one so explaining isn't easy.

    The query should update the value columns based on two conditions;

    loading.prod_id = target.prod_id
    target.shelf_id = select shelf_id from Shelf to Store Assignment where store_id = loading table.store_id


  • Registered Users Posts: 2,024 ✭✭✭Colonel Panic


    In MS SQL I do this kind of thing by updating the table from a select with a join on whatever else I need.

    What I usually do, is build the results I want first and use some thing like:
    update ATable set ATable.Column = SomeDerivedTable.Column from ATable as T inner join <stuff>
    

    That might point you in the right direction?


  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    In MS SQL I do this kind of thing by updating the table from a select with a join on whatever else I need.

    What I usually do, is build the results I want first and use some thing like:
    update ATable set ATable.Column = SomeDerivedTable.Column from ATable as T inner join <stuff>
    

    That might point you in the right direction?

    Will that method cope with multiple values from SomeDerivedTable.Column? E.g in my example there could be multiple shelves assigned to one store.


  • Registered Users Posts: 2,024 ✭✭✭Colonel Panic


    It will if you can manipulate the source data the way you want. I don't know anything about your data!


  • Advertisement
Advertisement