Connecting Tech Pros Worldwide Help | Site Map

update based on subqueries

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: 4 Weeks Ago
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.  
Reply