View previous topic :: View next topic |
Author |
Message |
anbesivam Beginner
Joined: 09 Aug 2006 Posts: 66 Topics: 14
|
Posted: Fri Jul 15, 2011 11:33 am Post subject: Help needed on creating Update query |
|
|
Hi,
I am getting 1000 records from 4 tables and I need to update perticular column in the 4th table.
For example, I am getting results from Table A, B, C & D using Joins and based on conditions.
Code: |
Col 1 (Tab A) Col2 (Tab B) Col 3 (Tab 3) Col 4 (Tab 4)
--------------- -------------- ----------------- ----------------
xxxxx 111 2222 15.07.2011
YYYYY 111 2222 15.07.2011 |
In this, I need to update only the Col 4 (Table 4) to 18.07.2011.
I have tried some combination with Update statement. But it is not working out.. Please guide me.
Thank you very much for your time. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Fri Jul 15, 2011 12:20 pm Post subject: |
|
|
anbesivam,
Show us the select statement of joining the 4 tables and how you are getting the results. Do you need the 4 columns or your primary goal is to update the COL4 ?
Kolusu |
|
Back to top |
|
 |
CZerfas Intermediate
Joined: 31 Jan 2003 Posts: 211 Topics: 8
|
Posted: Mon Jul 18, 2011 3:05 am Post subject: |
|
|
The main problem with the update statement is, that you don't have a FROM clause where you could list more than one table.
That means, that in case of the need of accessing more than one table, you have to put these into subselects (EXIST queries) within the WHERE clause of your UPDATE statement. That doesn't make your statement more readable but gives you the desired results.
regards
Christian |
|
Back to top |
|
 |
GuyC Supermod
Joined: 27 May 2011 Posts: 35 Topics: 0
|
Posted: Mon Jul 18, 2011 5:11 am Post subject: |
|
|
in other words, use a correlated subquery:
Code: | update tab1 A set (col4,col5,col6) =
(select b.col4,b.col5,b.col6 from anyjoin B where A.pk = b.pk)
where exists
(select b.col4,b.col5,b.col6 from anyjoin B where a.pk = b.pk) |
|
|
Back to top |
|
 |
anbesivam Beginner
Joined: 09 Aug 2006 Posts: 66 Topics: 14
|
Posted: Tue Jul 19, 2011 5:43 am Post subject: |
|
|
Thank you very much all of you for the detailed useful reply.
As the update query getting really complecated, we added some selection criteria to reduce the 4th table's results to less than 50 records and manually updated the dates. |
|
Back to top |
|
 |
|
|