I have two tables: teams, and persons.
table teams have three columns, id, name, leader
table persons have these columns: hash, team_id
teams.leader is a MD5 hash that must match persons.hash in order to determine which person is leader of a given team.
I need to run a query on MySQL that does the following:
1) Retrieve all the leaders of a team, and the team id:
SELECT `id`,`leader` FROM `teams`;
2) Use such information to update team_id on table persons
This is my current Query:
SELECT id FROM teams INNER JOIN persons ON teams.leader = persons.hash
but I haven’t been able to come up with a solution that allows me update column team_id with the corresponding leader.
I’ve been thinking probably using cursors, but not sure about it.
Any ideas?
You can use the multiple table
UPDATEsyntax to join the tables: