I have a table of users, `users`.
In the table `users` there is a row which stores clicks, `users`.`clicks`.
Each user has it's own referrer, `users`.`referrer_id` which refrences the referring user's id.
In the referring user's row, I would like a field to store referral clicks, `users`.`referral_clicks`.
I would like `users`.`referral_clicks` to be updated each time that a child user's `users`.`clicks` field is changed.
Is this easily possible in MySQL?
Is this more efficient than something like:
Expand|Select|Wrap|Line Numbers
- SELECT SUM(`users`.`clicks`) FROM `users` WHERE `users`.`referrer_id` = 1;
Expand|Select|Wrap|Line Numbers
- SELECT `users`.`referral_clicks`) FROM `users` WHERE `users`.`id` = 1;
Ben Manns