Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts

    update/insert one table upon data in another

    reason: having a huge table which slows down db, need to do analyse daily and add that to existing analytics (avoid analyse on huge bunch of data each day)

    table a (existing analyticsa)
    Code:
    a  5
    b  10
    d  30
    table b (today analytics)
    Code:
    a  5
    b  10
    c  15
    as a result of 'join' of those 2 tables a should become:

    table a
    Code:
    a  10
    b  20
    c  15
    d  30
    How to go about that most efficently ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    I'd be curious to hear if there is an efficient MySQL solution, but this sounds like a processing thing, and with that the solution would be to pull, sum, and insert.

    I don't know if there is a method to sum where key's match.

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts
    On second thought:


    Pseudocode:
    Code:
    insert into a
    select from b
    ON DUPLICATE KEY UPDATE
    sum_field =  (a.sum_ + b.sum),
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •