I want to loop through several mysql tables that have similar names like
table_1_user
table_2_user
table_3_user
In sum I want an iterator count up to 20 so that in the end I will have fired some queries over all 20 tables. As you can see the only difference is the number within the name. So I made some research and found this answer by Martynnw. One drawback I have to mention is that there are one or two ids missing so it can be that we have a table_3 and a table_5 but the table_4 might be missing. So I would also like to include a check if the table exists (if necessary at all).
I believe it has to be possible to do something like this:
Declare @Id int
While @Id < 20
Begin
UPDATE table_@Id_user SET option_value = 'mychange' WHERE my_id = 123;
End
But I can't quite figure it out yet.
Any help would be very much appreciated!
Thanks a lot in advance!