Solved

plsql update with join

Posted on 2014-04-08
3
638 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle SQL - Query help 7 54
ODBC in excel 2016 in Windows 10 via VBA 16 74
T-SQL Query to include null values 3 29
SQL Error - Query 6 25
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
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 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…
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.

770 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