mysql - Make trigger update the rows I want -


i struggling trigger update second table based on first table being updated.

i have tried this:

delimiter // each row begin update phpfb_picks set points = new.value username = user , gameid = gameid end; // delimiter; 

but error syntax.

if do:

update phpfb_picks set points = new.value username = user , gameid = gameid 

this works point. updates users records same value updated.

what want is, when value updated on table a, want update table b records user, 'value' table pushed 'points' of table b user, regardless if actual record updated.

if record user updated, update of table b records same value based on username , gameid

so if table has following records: username - test gameid - 1 value - 1

username - test gameid - 2 value - 2

when value row 1 updated 3, want update table b current values table user.

is possible?

update:

table (allpoints) has columns: username gameid value  table b (phpfb_picks) has columns: user gameid points  allpoints.username = phpfb_picks.user allpoints.gameid = phpfb_picks.gameid allpoints.value = phpfb_picks.points 

whenever update made allpoints, want records specific user update specific records user in phpfb_picks, passing allpoints.value phpfb_picks.points based on user , gameid

try trigger:

delimiter $$ create trigger update_phpfb_picks      after update on allpoints each row      begin         update phpfb_picks         inner join allpoints on allpoints.username = phpfb_picks.username ,                                 allpoints.gameid = phpfb_picks.gameid         set phpfb_picks.points = allpoints.value         phpfb_picks.username = new.username;     end; $$ delimiter ; 

for each row updated in allpoints, rows in phpfb_picks same username of updated row updated respective value of points present in allpoints value. trigger after update newly updated value in allpoints set in phpfb_picks.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -