473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

update based on subqueries

I have a table T(col1, col2, col3, col4) and I run sub-queries on it that results on two disjunct sets of data. Now I have to update col2 from the first set of data to the values from col3 of the second subquery.

How should the update query be?

I tried something like

update subset_d set subset_d.col2=subset_c.col3
where d.col1=c.col1 and
d.col4=d.col4

The subset_c and subset_d are run on the same table

In my situation the table HORATIU_NETWORK_AREA and the subqueries are d and c. The query I tried is
Expand|Select|Wrap|Line Numbers
  1.  
  2. update d set d.eff_stop_ts= c.eff_start_ts from
  3. (
  4.  select a.NETWORK_AREA_ID, a.CELL_ID, a.LAC_ID,     to_char(a.EFF_STOP_TS,'dd-mm-yyyy hh:mi:ss'), a.TIME_ZONE_CD, a.BID, to_char(a.EFF_START_TS,'dd-mm-yyyy hh:mi:ss'), a.NETWORK_AREA_PROV_STATE_CD, a.NETWORK_AREA_CITY_NM, a.SWITCH_ID, a.CREATE_USER_ID,a.LAST_UPDT_USER_ID, to_char(a.CREATE_TS,'dd-mm-yyyy hh:mi:ss'), to_char(a.LAST_UPDT_TS,'dd-mm-yyyy hh:mi:ss')
  5. from
  6. HORATIU_NETWORK_AREA
  7.  
  8. a,
  9. (
  10. select hna1.CELL_ID, hna1.LAC_ID, count(*) from
  11. HORATIU_NETWORK_AREA hna1
  12.  
  13. group by hna1.CELL_ID,hna1.LAC_ID having count(*)>1
  14. ) b
  15. where
  16. a.cell_id = b.cell_id and
  17. a.lac_id=b.lac_id and
  18. a.eff_stop_ts >= to_date('01-01-2029 00:00:00', 'dd-mm-yyyy hh24:mi:ss') and
  19. a.eff_stop_ts <= to_date('01-01-9999 00:00:00', 'dd-mm-yyyy hh24:mi:ss')
  20. order by a.cell_id, a.lac_id
  21. ) d,
  22. (
  23. select a.NETWORK_AREA_ID, a.CELL_ID, a.LAC_ID, to_char(a.EFF_STOP_TS,'dd-mm-yyyy hh:mi:ss'), a.TIME_ZONE_CD, a.BID, to_char(a.EFF_START_TS,'dd-mm-yyyy hh:mi:ss'), a.NETWORK_AREA_PROV_STATE_CD, a.NETWORK_AREA_CITY_NM, a.SWITCH_ID, a.CREATE_USER_ID,a.LAST_UPDT_USER_ID, to_char(a.CREATE_TS,'dd-mm-yyyy hh:mi:ss'), to_char(a.LAST_UPDT_TS,'dd-mm-yyyy hh:mi:ss')
  24. from HORATIU_NETWORK_AREA a,
  25. (
  26. select hna1.CELL_ID, hna1.LAC_ID, count(*) from
  27. HORATIU_NETWORK_AREA hna1
  28.  
  29. group by hna1.CELL_ID,hna1.LAC_ID having count(*)>1) b
  30. where
  31. a.cell_id = b.cell_id and
  32. a.lac_id=b.lac_id and
  33. a.eff_stop_ts >= to_date('01-01-9999 00:00:00', 'dd-mm-yyyy hh24:mi:ss')
  34. order by a.cell_id, a.lac_id
  35. ) c
  36. where
  37. c.cell_id = d.cell_id and
  38. c.lac_id = c.lac_id
  39. .lac_id=d.lac_id
  40.  
Oct 25 '09 #1
0 1551

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Don | last post by:
Hi, I am moving from Sybase to Oracle and I used to be able to do update statement like this in Sybase: UPDATE TABLE1 SET T1.field1 = T2.field2 FROM TABLE1 T1, TABLE2 T2 WHERE T1.field2...
5
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET...
10
by: sqlgoogle | last post by:
Hi I'm trying to update a db based on the select statement which has ORDER BY in it. And due to that I'm getting error which states that Server: Msg 1033, Level 15, State 1, Line 13 The ORDER...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
7
by: robert | last post by:
i need to update a column which is a member of the PK on this table. there are some thousands of rows to be updated, many more thousand already in the table. so, i get a constraint violation...
5
by: Dave Smithz | last post by:
Hi there, Been working on an evolving DB program for a while now. Suddenly I have come across a situation where I need to update a table based on a group by query. For example, I have a table...
9
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something...
5
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.