Besides the issue with potentilly locatin in the wrong table:
Taking two steps back from a detail to the real world problem, it looks like you want to put a list of players into teams and to avoid one player being put into a team twice, plus a player being put into several teams.
At another thread I already proposed a table design, that would sole that concern: Having a teamid in a player table a player can only be put into one team, and only be put in there once.
It's really just a matter of the right data structures to simplify code and solve problems by making wrong, redundant or contradictory data impossible.
So lets assume you have a list of players, permanent, a list of members of a sports clu, for example. Now you have event, tournaments, matches and you want to put the members into teams for that day. That suggests following tables:
teams
id, number
players
id, name, teamid, further personal data
Now, any player not yet having a teamid is i no team, but any player having a teamid is in that team, and in that team only. See?
And if you need that for several events, and have permanent player data, eg members of a sports club being put into different teams at different events, that suggests the following structure:
players
id, name, further personal data
events
id, name, date
teams
id, number, eventid
teamplayers
id, teamid, playerid
Here a candidate type index on bintoc(teamid)+bintoc(playerid) will care for no double player in a team.
This can be advanced as you like, but in itself it would already solve many of the problems. You seem to group data by copying it into a teable, you seem to create a table per team and this already makes your code more complex than it needs to be, instead of working on several tables you just use the teamplayers filter for a teamid to get a single team, or SELECT ...WHERE teamid = x
This is how tables are meant, they store all equally strucutred data and partition and group it, you don't do the latter with creating tables for each event and each team, that's not good design at all.
Bye, Olaf.