How do I LIMIT the number of rows in a DELETE with DB2?

后端 未结 9 582
醉梦人生
醉梦人生 2021-01-11 17:09

I want to add a security on a sensitive table when I delete lines with an SQL request on a DB2 table.

I want to mimic the way MySQL allows you to limit the numbers o

9条回答
  •  鱼传尺愫
    2021-01-11 17:59

    If your primary key has multiple values, or you just need multiple values as the condition, this is the query that works:

    DELETE FROM TABLE
    WHERE (COLUMN1, COLUMN2) IN (
        SELECT COLUMN1, COLUMN2 FROM TABLE
        WHERE SOME_COLUMN='THIS'
        AND SOME_OTHER_COLUMN LIKE 'THAT%'
        FETCH FIRST 10 ROWS ONLY)
    

提交回复
热议问题