Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Starting Member

39 Posts

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

Contestant Table:

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.

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

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.

Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000