I have the tables below and
- tempaddresstable
- account
- premise
- address
Here is the link of details(id of account = account_fk of premise) (address_fk of premise = id of address)
So only goal is to update all the records info from tempaddresstable to address table
I have tried the below query but I am getting error
UPDATE ADDRESS AD
SET AD.ADDRESS1 =
(SELECT (B.TEMPADDRESS1)
FROM tempAddressTable B,
ADDRESS AD
WHERE AD.ID =
(SELECT (P.ADDRESS_FK)
FROM ACCOUNT A
LEFT JOIN tempAddressTable B ON A.EXT_REF = B.TEMPEXTREF
LEFT JOIN PREMISE P ON A.ID = P.ACCOUNT_FK
LEFT JOIN ADDRESS AD ON AD.ID = P.ADDRESS_FK
WHERE A.EXT_REF = B.TEMPEXTREF ))
WHERE EXISTS
(SELECT 1
FROM tempAddressTable B
WHERE AD.ID =
(SELECT DISTINCT max(P.ADDRESS_FK)
FROM ACCOUNT A
LEFT JOIN PREMISE P ON A.ID = P.ACCOUNT_FK
LEFT JOIN tempAddressTable B ON A.EXT_REF = B.TEMPEXTREF
WHERE A.EXT_REF = B.TEMPEXTREF ));
Error :
SQL Error: ORA-01427: single-row subquery returns more than one row 01427. 00000 - "single-row subquery returns more than one row"
*Cause:
*Action:
Details of the table
- tempaddresstable
- account
- premise
- address
tempaddresstable
+------------+----------------------------+
| TEMPEXTREF | TEMPADDRESS1 |
+------------+----------------------------+
| 34 | 101 DRCSG117432RES RD TEST |
| 35 | 102 DRCSG117 |
| 36 | 100 DRCSG117432RES RD |
+------------+----------------------------+
account
+---------+---------+
| ID | EXT_REF |
+---------+---------+
| 1041261 | 34 |
| 1041262 | 35 |
| 1041263 | 36 |
+---------+---------+
premise
+---------+------------+------------+
| ID | ACCOUNT_FK | ADDRESS_FK |
+---------+------------+------------+
| 1044610 | 1041261 | 1041502 |
| 1044611 | 1041262 | 1041503 |
| 1044612 | 1041263 | 1041504 |
+---------+------------+------------+
address
+---------+----------+
| ID | ADDRESS1 |
+---------+----------+
| 1041502 | test |
| 1041503 | test |
| 1041504 | test |
+---------+----------+