MySQL - UPDATE query based on SELECT Query

后端 未结 11 2337
既然无缘
既然无缘 2020-11-21 23:58

I need to check (from the same table) if there is an association between two events based on date-time.

One set of data will contain the ending date-time of certain

11条回答
  •  情书的邮戳
    2020-11-22 00:50

    You can actually do this one of two ways:

    MySQL update join syntax:

    UPDATE tableA a
    INNER JOIN tableB b ON a.name_a = b.name_b
    SET validation_check = if(start_dts > end_dts, 'VALID', '')
    -- where clause can go here
    

    ANSI SQL syntax:

    UPDATE tableA SET validation_check = 
        (SELECT if(start_DTS > end_DTS, 'VALID', '') AS validation_check
            FROM tableA
            INNER JOIN tableB ON name_A = name_B
            WHERE id_A = tableA.id_A)
    

    Pick whichever one seems most natural to you.

提交回复
热议问题