Home » SQL & PL/SQL » SQL & PL/SQL » query correction required (11g)
query correction required [message #643436] Wed, 07 October 2015 09:05 Go to next message
amy.wilson
Messages: 39
Registered: September 2015
Location: Www
Member
Hi All,

I have written a query to update a column..

update urole set unmatched_records= (select concat(regname,ID) from urole where rcount>1) where unmatched_data is null;


I have data as follows

ID    DNAME      REGNAME       RCOUNT     Unmatched_Data
--------------------------------------------------------
1     Agency	  Agency	1          <Null>
2     Eastern	  Atlanta	1
3     Eastern	  Boston	1
4     Business 	  Business 	1
5     Canada	  Canada	2
6     Eastern	  Canada	2
7     Central	  Central	1
8     Central	  Central Region1
9     Central	  Chicago	1
10    Central	  Cincinnati	1
11    Marketing	  Marketing	1
12    Media	  Media	1
13    Media	 Media Eastern	1
14    Media	 Media Western	1
15    Custom Pub Custom Pub	2
16    Eastern	 Custom Pub	2     



Here unmatched_data column is null.

so I would like to write a query to update UNMATCHED_DATA column by concatenating REGNAME and ID columns where REGCOUNT>1

Can you have a look and advise me a query.

Thanks

Re: query correction required [message #643440 is a reply to message #643436] Wed, 07 October 2015 09:36 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
It's not all obvious what the expected result is.
either it's this:
update urole set unmatched_records= concat(regname,ID) where unmatched_data is null and rcount>1;

Or you need to explain which records should be used to update which other records.
Re: query correction required [message #643447 is a reply to message #643436] Wed, 07 October 2015 10:14 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
Your subquery needs to be scalar, or you will get an "ORA-01427: single-row subquery returns more than one row".
Re: query correction required [message #643448 is a reply to message #643440] Wed, 07 October 2015 10:19 Go to previous messageGo to next message
amy.wilson
Messages: 39
Registered: September 2015
Location: Www
Member
Appreciate your quick response.

It worked for me. Smile
Re: query correction required [message #643453 is a reply to message #643448] Wed, 07 October 2015 10:39 Go to previous messageGo to next message
sandeep_orafaq
Messages: 88
Registered: September 2014
Member
amy.wilson wrote on Wed, 07 October 2015 10:19
Appreciate your quick response.

It worked for me. Smile



We have no idea what worked for you. At least what was supposed to be done.
Re: query correction required [message #643459 is a reply to message #643453] Wed, 07 October 2015 23:21 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

In addition, With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Previous Topic: CTE Queries
Next Topic: required date month year query
Goto Forum:
  


Current Time: Fri Apr 19 16:21:26 CDT 2024