0

I want to update a column named 'FLAG' and set its value as C when the records from two different tables have a match on a few conditions. Please see the below sample of what I'm trying to achieve in Teradata.

UPDATE DB.TABLENAME SET FLAG = 'C'
WHERE DB.TABLENAME A INNER JOIN DB2.TABLENAME2 B 
ON A.POLICY_NUMBER = SUBSTR(B.POLICY_NUMBER,5,8) AND
A.IDENTIFIER = B.IDENTIFIER AND A.NUMBER = B.NUMBER;

I'm sort of new to teradata and not able to figure out a way to do this.

I've tried this:

UPDATE A
FROM DB.TABLENAME A, DB2.TABLENAME2 B 
SET FLAG = 'C'
WHERE A.POLICY_NUMBER = SUBSTR(B.POLICY_NUMBER,5,8) 
AND A.IDENTIFIER = B.IDENTIFIER 
AND A.NUMBER = B.NUMBER;

But this gives me error as "Target row updated by multiple source rows".

2
  • One option is to use a subquery to eliminate the duplicate match values: FROM DB.TABLENAME A, (SELECT DISTINCT IDENTIFIER, NUMBER, SUBSTR(POLICY_NUMBER,5,8) AS POLICY_SUBSTR FROM DB2.TABLENAME2) B Commented Dec 8, 2023 at 18:45
  • You need to understand (in your data) why this is happening. You may need to de-dupe as Fred is suggesting, you may need additional criteria in your join, etc. Commented Dec 8, 2023 at 20:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.