Is it possible to create a trigger in mysql for this:
I have a table like this
Column1_id Column2_val
1 2
2 2
Second table
Column1_id1 Column2_id2
1 2
So pretty much on update or insert if twos rows have the same value for Column2_val
I want to insert the ids of that into the second table. any help would be greatly appriciated.
I wrote this but it doesn't seem to be working am i doing something wrong?
BEGIN
set @user_id_update = (SELECT Column1_id from users where in_play = 2 LIMIT 1);
INSERT INTO player_pairs(PLAYER1_ID, PLAYER2_ID, GAME_ID)
VALUES (new.Column1_id, @user_id_update, 2);
UPDATE users SET in_play = 1 where Column1_id in(@user_id_update, new.user_id);
END