Teradata Update Table from Select Statement

前端 未结 2 744
無奈伤痛
無奈伤痛 2021-01-06 13:03

Sorry if the title is unclear. Basically I\'m trying to select certain records from multiple tables then update a certain column value for the returned records.

T-SQ

相关标签:
2条回答
  • 2021-01-06 13:44

    Have you tried the following syntax with Teradata:

    UPDATE CUSTOMERS C1
      FROM (SELECT C2.LINK_ID
              FROM CUSTOMERS C2
             INNER JOIN RESTAURANTS R2
                ON C2.LINK_ID = R2.LINK_ID
            WHERE R2.REST_TYPE = 'DINER'
              AND C2.LIKES_US IS NULL) D1
       SET LIKES_US = 'Y'
     WHERE C1.LINK_ID = C2.LINK_ID
    
    0 讨论(0)
  • 2021-01-06 13:57

    I think that in this specific case, the below query will perform a little better since it needs one less join.

    UPDATE C
    FROM CUSTOMERS  C, RESTAURANTS R
    SET LIKES_US = 'Y'
    WHERE 
    C.LINK_ID = R.LINK_ID
    AND R.REST_TYPE = 'DINER'
    AND C.LIKES_US IS NULL
    
    0 讨论(0)
提交回复
热议问题