Solved

Help with update statement

Posted on 2014-02-12
5
364 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-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 74

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 74

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

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…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to recover a database from a user managed backup

751 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