SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Adding values from different tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

damdeok
Starting Member

39 Posts

Posted - 11/10/2012 :  14:26:52  Show Profile  Reply with Quote
Friends, I have these tables:

Contestant Table:
Winner
Peter

Group Table:
Id Name Score Union
1 Bryan 3 77
2 Mary 1 20
3 Peter 5 77
4 Joseph 2 25
5 John 6 77

I want to give additional score of 5 to Peter on Group Table. So, I came up with this query.

UPDATE Group 
SET Score = Score+5
FROM 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 - 11/12/2012 :  10:46:40  Show Profile  Reply with Quote
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 + 5
FROM Group
where Union=(
select g.union
FROM Group g
join 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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000