Reputation: 3
I want to iterate through a mysql table and for each row I want to execute a command with the ID of the current row.
So in simple code this needs to be done:
FOR EACH ROW IN TABLE
SQL -> "UPDATE TABLE SET Value= '5' WHERE ID='ROW_ID'"
END FOR
I've looked on the internet but I encountered very vague answers. Can somebody help me with the SQL Command I need to use? Thanks in advance.
Upvotes: 0
Views: 360
Reputation: 3
I got it working using this code:
UPDATE wWEEK JOIN STANDARD ON STANDARD.ID = wWEEK.ID SET
wWEEK.Column1 = STANDARD.Column1,
wWEEK.Column2 = STANDARD.Column2,
wWEEK.Column3 = STANDARD.Column3,
wWEEK.Column4 = STANDARD.Column4,
wWEEK.Column5 = STANDARD.Column5,
wWEEK.Column6 = STANDARD.Column6
Upvotes: 0
Reputation: 62
Are you expecting this ,
UPDATE TABLE t SET Value = (select row_id from another_table)
You can use other table data.
Upvotes: 0
Reputation: 1271171
Just use update
:
UPDATE TABLE t
SET Value = '5'
This will update all rows in the table. Use the where
statement only when you want to filter the rows being updated.
Upvotes: 1