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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 multiple rows query help

Author  Topic 

maddyslayer
Yak Posting Veteran

57 Posts

Posted - 2013-04-22 : 15:56:06
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
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-04-22 : 16:23:32
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-23 : 01:07:21
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
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-23 : 01:15:28
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
   

- Advertisement -