SQL: making queries from multiple tables
I have never encountered a similar situation before, and I cannot find relative documentation:
Suppose I have two tables. For simplicity, suppose that on one table (which is temporary) I have these columns: name, votes And suppose that on the other table i have: name, total_votes, and other updated details (this table is a permanent up2date version of first table). My aim is that for each name in table 1, I grab the relative "votes" value and inject it in Table 2 with the matching "name" column replacing the previous "total_votes' value... How can I do it? |
call your temp table t and your perm table p
update t,p set p.TotVotes=t.Votes where t.Name=p.Name; you might even be able to do update p set p.TotVotes=t.Votes join t using (Name); <edit> if you wanted to add votes to total votes then obviously replace "p.TotVotes=t.Votes" with "p.TotVotes=p.TotVotes+t.Votes" </edit> |
All times are GMT -5. The time now is 11:28 AM. |