Solved

Help with update statement

Posted on 2014-02-12
5
360 Views
Last Modified: 2014-02-12
Experts,

I want to update my status field to 4 on the table called credit_master where the below query gives a result.

detail and master are linked by column cid

select 
  m.cid,
  count(distinct d.status) stat
from credit_master m, 
         credit_detail d 
where m.cid = d.cid
group by m.cid
having count(distinct d.status) =2

Open in new window

0
Comment
Question by:FutureDBA-
  • 3
  • 2
5 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 39855068
>>> where the below query gives a result.

what does that mean?
0
 

Author Comment

by:FutureDBA-
ID: 39855074
This query

select 
  m.cid,
  count(distinct d.status) stat
from credit_master m, 
         credit_detail d 
where m.cid = d.cid
group by m.cid
having count(distinct d.status) =2

Open in new window


Gives me these results
m.cid	status
--------------
172	2
135	2
137	2
149	2
161	2

Open in new window


I want to update m.status to 4 where m.cid = status results havind a 2 on  d.status
0
 

Author Comment

by:FutureDBA-
ID: 39855084
Does this seem right?
update credit_master m set status = 5
where exists 
(select 
  count(distinct d.status) stat
from credit_detail d 
where m.cid = d.cid
group by m.cid
having count(distinct d.status) > 1)

Open in new window

0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39855085
I think this is what you're trying to say

Given a set of cid values returned by above query,  Update all records with those cids to status 4


UPDATE credit_master
   SET status = 4
 WHERE cid IN (SELECT m.cid
                 FROM credit_master m, credit_detail d
                WHERE m.cid = d.cid
               GROUP BY m.cid
               HAVING COUNT(DISTINCT d.status) = 2)
0
 

Author Comment

by:FutureDBA-
ID: 39855087
Correct.

Thanks,

I think I was on the right path.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
null value 15 92
Best RAID for a BDD Oracle 4 59
Converting a row into a column 2 43
use lov values 2 18
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now