Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am updating:
SQL
UPDATE table1 A SET (A.COLUMN_NAME) = (SELECT 1 FROM table2 WHERE A.COLUMN <> B.COLUMN)

But it throws an error
SUBQUERY CAN RETURN SINGLE VALUE

Please suggest how to update.
Posted
Updated 26-Sep-14 23:27pm
v2
Comments
George Jonsson 27-Sep-14 5:29am    
I updated your question.
Don't put the whole question in the title and don't use all capital letters.
It is shouting, and quite impolite.
George Jonsson 27-Sep-14 5:29am    
And I am not sure your error message is correct.
Jörgen Andersson 27-Sep-14 5:35am    
Before we can suggest how to update you need to elaborate on what you want to achieve.
Also state what database engine you're using.
naveenece9 27-Sep-14 5:57am    
oracle

I want to update 1 from subquery when condition is <>. Please suggest if you can
Jörgen Andersson 27-Sep-14 6:10am    
As George already questioned, is your error message correct?
Your update needs a subquery that's returning exactly one row per row to update.
Not equals will return all rows that fits the condition.
Do you have any IDs that can identify a single row?

1 solution

As has been suggested, the subquery,
SELECT 1 FROM table2 WHERE A.COLUMN <> B.COLUMN
, is probably returning more than 1 row. So, there is more than 1 row where A.COLUMN <> B.COLUMN.

If you want a single value returned, change the subquery.

If possible, try to run the subquery by itself to see what it is returning.
 
Share this answer
 

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