Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-24-2012, 02:06 PM   PM User | #1
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
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
BubikolRamios is offline   Reply With Quote
Old 02-24-2012, 03:29 PM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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.
Keleth is offline   Reply With Quote
Old 02-24-2012, 05:42 PM   PM User | #3
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
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
BubikolRamios is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:20 PM.


Advertisement
Log in to turn off these ads.