Solved

plsql update with join

Posted on 2014-04-08
3
628 Views
Last Modified: 2014-04-08
Hi,

I created a update inner join as below (as per examples I've seen) and that seems to work fine

UPDATE table1 c
SET c.name =
      ( SELECT t.name
        FROM table2 t
        WHERE c.id = t.id
      )
WHERE EXISTS
        ( SELECT 1
          FROM table2 t
          WHERE c.id = t.id 
        )

Open in new window


However, that is not the whole story, since I need to be able to apply a further filter, but that filter needs to be on the table1 table. Basically that filter would look like

INNER JOIN table3 k on k.id = c.id
WHERE k.id2 = 1 and k.id3 = 2

Open in new window


so that I'm not updating the entire table1 but only a subset of table1 based on the join with table3 (if that makes sense)...

where does that third join go in this query?

thanks, Aiden
0
Comment
Question by:AidenA
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 39985916
I had written this article:
http://www.experts-exchange.com/Database/Miscellaneous/A_1517-UPDATES-with-JOIN-for-everybody.html

anyhow, you can add indeed more EXISTS() and conditions ...
UPDATE table1 c
SET c.name =
      ( SELECT t.name
        FROM table2 t
        WHERE c.id = t.id
      )
WHERE EXISTS
        ( SELECT 1
          FROM table2 t
          WHERE c.id = t.id 
        )
   AND EXISTS 
      ( SELECT 1
             FROM  table3 k 
               WHERE k.id = c.id
                AND k.id2 = 1 
          AND k.id3 = 2
   )

Open in new window


INNER JOIN
0
 
LVL 15

Assisted Solution

by:Devinder Singh Virdi
Devinder Singh Virdi earned 100 total points
ID: 39986369
Looks like you are doing bulk update, therefore, if table is very big, you may have some kind of performance problem.
Therefore another method you can use is to create Temp table with required columns. Then use update command.
0
 

Author Closing Comment

by:AidenA
ID: 39986693
thanks for that, that seemed to work fine, thanks for link to your article, I'll take a look. Was a bit slow though, will keep your comments in mind
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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

932 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

10 Experts available now in Live!

Get 1:1 Help Now