Netezza UPDATE from one table to another
Asked Answered
G

1

6

This is my query that does not work in Netezza:

UPDATE TABLE1 A
SET A.COL1= (SELECT DISTINCT B.COL1 FROM TABLE2 B WHERE B.ID= A.ID AND B.DeptID=104)
WHERE A.DeptID=3

How do I re-write this query? Please help.

Greenroom answered 6/8, 2014 at 16:48 Comment(2)
What error message are you getting ?Faxun
Netezza doesn't support subqueries like this...use join syntax instead.Khat
P
13
UPDATE TABLE1 A
SET A.COL1 = B.COL1
FROM TABLE2 B
WHERE
A.ID = B.ID AND 
A.DeptID = 3 AND 
B.DeptID = 104;
Princess answered 6/8, 2014 at 16:50 Comment(7)
I get an error ^ found "INNER" (at char 57) expecting a keywordGreenroom
sorry, forgot the from clause. I edited it - try it now.Princess
Get another error error ^ found "B" (at char 157) expecting a keywordGreenroom
Donal thanks for helping out. I was missing and AND crrected that but am getting another ERROR [42S02] ERROR: relation does not exist DB.USER.AGreenroom
That syntax may not work with Netezza. I have changed it to use a different syntaxPrincess
Sorry still no luck. ERROR: Update canceled: attempt to update a target row with values from multiple join rowsGreenroom
That means it is working. It just means that there are multiple rows in Table2 that match the criteria in the where clause for 1 row in Table1. I cannot see what your data is like, so I am not sure how to modify the where clause to return just 1 row from Table2 for each row in Table1.Princess

© 2022 - 2024 — McMap. All rights reserved.