Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 multiple rows query help
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

maddyslayer
Yak Posting Veteran

57 Posts

Posted - 04/22/2013 :  15:56:06  Show Profile  Reply with Quote
I run the following query

update products set
product_id = (select c.product_id from thirdparty_table a inner join Email c on a.Email = c.email_address)
where exists (select product_id from productswhere id != '0')

when i run the above query, I get the following error
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

How do I solve this?What needs to be changed in query?

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/22/2013 :  16:23:32  Show Profile  Reply with Quote
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 04/23/2013 :  01:07:21  Show Profile  Reply with Quote
The reason for above error is that sub query might return more than one product_id... (select c.product_id from thirdparty_table a inner join Email c on a.Email = c.email_address)
You can use the following methods:
http://data.bangtech.com/sql/sql_update_with_correlated_subquery.htm


--
Chandu

Edited by - bandi on 04/23/2013 01:07:45
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 04/23/2013 :  01:15:28  Show Profile  Reply with Quote
Duplicate thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=184766#722065

NOTE: Do not post duplicate threads..

--
Chandu
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