Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
damdeok
Starting Member
39 Posts |
Posted - 2012-11-10 : 14:26:52
|
Friends, I have these tables:Contestant Table:WinnerPeterGroup Table:Id Name Score Union1 Bryan 3 772 Mary 1 203 Peter 5 774 Joseph 2 255 John 6 77I want to give additional score of 5 to Peter on Group Table. So, I came up with this query.UPDATE Group SET Score = Score+5FROM Contestant, Group WHERE Contestant.Winner = Group.Name Now, I want also to give additional score of 5 to the same Union as Peter which is 77.How can I integrate it as one query to my existing query? |
|
Mike Jackson
Starting Member
37 Posts |
Posted - 2012-11-12 : 10:46:40
|
You can't integrate it with the current query because your join (Contestant.Winner = Group.Name) exclueds all other records except Peter.but you could run 2 queries, something like UPDATE Group SET Score = Score + 5FROM Groupwhere Union=(select g.union FROM Group gjoin Contestant c on C.Winner = G.Name)but you would have to run this one first. Otherwise your query would change the [union] field and it would no longer be 77 and there would be no matches.Mike |
|
|
|
|
|