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
 General SQL Server Forums
 New to SQL Server Programming
 TROUBLESHOOT: Update Using Nested Select Statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MMMY
Starting Member

14 Posts

Posted - 10/04/2012 :  17:33:37  Show Profile  Reply with Quote
Hello, I am just trying to understand the logic behind this. Below are two example tables.

TABLE TEAM

NAME	COLOR
Bob	Blue
Jill	Blue
Fred	Red


TABLE REF

PERSON	
Jill


I want to update TEAM so any name that appears in REF is updated to Red.

Here is the query:

UPDATE TEAM
SET COLOR = 'Red'
WHERE NAME IN (
SELECT PEOPLE FROM REF
)

Note that PEOPLE is not a valid column in REF. If you run the nested select query it will bring an error. However, if you run the entire update statement, it will update ALL records to Red.

Can anyone explain the logic behind this?

Thanks!

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 10/04/2012 :  17:42:11  Show Profile  Reply with Quote
I don't see a People column in either table is that the right query or a typo?
Go to Top of Page

chadmat
The Chadinator

USA
1974 Posts

Posted - 10/04/2012 :  17:45:32  Show Profile  Visit chadmat's Homepage  Reply with Quote
I don't think that it does. I just tried this and got the following error:

Msg 207, Level 16, State 1, Line 11
Invalid column name 'People'.

-Chad
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.09 seconds. Powered By: Snitz Forums 2000