Solved

Help with update statement

Posted on 2014-02-12
5
356 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
Comment Utility
>>> where the below query gives a result.

what does that mean?
0
 

Author Comment

by:FutureDBA-
Comment Utility
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-
Comment Utility
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
Comment Utility
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-
Comment Utility
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.

Join & Write a Comment

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  â€¦
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

763 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

6 Experts available now in Live!

Get 1:1 Help Now