Click here to Skip to main content
15,885,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I got the error like "at most one record can be returned by this subquery"

Please help me to solve this query
SQL
UPDATE UserMenu SET UserMenu.MenuOrderNo = MenuOrderNo-1 WHERE ((([MenuOrderNo])=(select MenuOrderNo from UserMenu where(((MenuID) =7) AND ((UserId)='1'))+1)) AND ((UserMenu.UserId)='1'))

thanks in advance


Sheethal
Posted
Updated 24-Aug-12 10:18am
v2

The (select MenuOrderNo from UserMenu where(((MenuID) =7) AND ((UserId)='1'))+1)) AND ((UserMenu.UserId)='1')) subquery returned more than one row. If this is normal, and your logic allows it, use IN instead of = before it, like this:
SQL
UPDATE UserMenu SET UserMenu.MenuOrderNo = MenuOrderNo-1 WHERE ((([MenuOrderNo]) IN (select MenuOrderNo from UserMenu where(((MenuID) =7) AND ((UserId)='1'))+1)) AND ((UserMenu.UserId)='1'))
 
Share this answer
 
v2
Comments
ridoy 24-Aug-12 16:26pm    
right..IN is good one..+5 from me
Maciej Los 24-Aug-12 17:00pm    
Good answer, my 5!
smsheethal 24-Aug-12 17:35pm    
thank you for your suggestion
The problem is in your comparison. You use equal comparison for MenuOrderNo so the select must fetch exactly 0 or 1 records. Now it returns more than one record.

Depending on your logic you either need to change the comparison or the select. If it's acceptable to update several rows then you should use IN operator, for example:
SQL
UPDATE UserMenu SET UserMenu.MenuOrderNo = MenuOrderNo-1 WHERE ((([MenuOrderNo]) IN (select MenuOrderNo from UserMenu where(((MenuID) =7) AND ((UserId)='1'))+1)) AND ((UserMenu.UserId)='1'))

If you need to update a single record, then go through the SELECT statement to see why it is returning multiple rows.
 
Share this answer
 
Comments
Maciej Los 24-Aug-12 17:00pm    
Good answer, my 5!
Wendelius 24-Aug-12 17:31pm    
Thanks :)
smsheethal 24-Aug-12 17:35pm    
Thank you for your suggestion
Wendelius 24-Aug-12 17:38pm    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900