Correct the update query for marking duplicate rows in DB2

Superman

I'm trying to update a column with the value 1 where the following criteria match.

UPDATE 
(SELECT TBL.KEY, TBL.IS_DUPLICATE FROM MYTABLE AS TBL JOIN
(SELECT TBL1.KEY FROM MYTABLE AS TBL1 GROUP BY TBL1.KEY HAVING COUNT(TBL1.KEY)>1) SELECTION 
ON SELECTION.KEY = TBL.KEY ORDER BY TBL.KEY ASC) OuterSelection
SET OuterSelection.IS_DUPLICATE = 1;

Here is the error I'm getting when running this query.

SQL Error [42807]: The target fullselect, view, typed table, materialized query table, range-clustered table, or staging table in the INSERT, DELETE, UPDATE, MERGE, or TRUNCATE statement is a target for which the requested operation is not permitted.. SQLCODE=-150, SQLSTATE=42807, DRIVER=4.16.53

Christian Cederquist

Problem was that the selection had to be matched in the WHERE clause, and the UPDATE should just specify the table. Here is the solution:

UPDATE TBL
SET IS_DUPLICATE=1
WHERE KEY IN (SELECT KEY
FROM TBL
GROUP BY KEY
HAVING COUNT(*) > 1); 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

DB2, optimize an update query

From Dev

Marking rows of table as duplicate if one column has duplicate values

From Dev

Check for duplicate rows in 2 columns before update

From Dev

MySQL query to update all "duplicate" rows except the latest one

From Dev

MySQL query to update all "duplicate" rows except the latest one

From Dev

How to update the same column for multiple rows in DB2

From Dev

Update duplicate rows

From Dev

Unable to Update rows of DataGridView from DB Query

From Dev

Query not updating the correct Rows

From Dev

Update duplicate rows except for one

From Dev

MySQL query returns duplicate rows

From Dev

Query to find duplicate rows in a table

From Dev

How to get row update count in a DB2 update query in node.js?

From Dev

MySQL ON DUPLICATE KEY UPDATE wth JOIN for multiple rows insert in single query

From Dev

Django admin: list not correct (duplicate rows)

From Dev

MySQL update query for duplicate entries

From Dev

mysql query to update duplicate entries

From Dev

Update Query For Duplicate Records Oracle

From Dev

PHP PDO MySQL Correct way to check if an update query succeeded when no rows are affected

From Dev

Is it possible from a DB2 (or any other sql) query to fetch rows selectively as shown below?

From Dev

Returning a default value when query does not return rows in DB2

From Dev

How to update exactly one record and select updated row in a single db2 query

From Dev

How to update exactly one record and select updated row in a single db2 query

From Dev

Marking duplicate values in new column

From Dev

Update table with duplicate rows in another table

From Dev

MySQL: Update all rows in 2 table matching results of another query

From Dev

sql server query for update rows which are multiple of 2

From Dev

linq query to update multiple rows

From Dev

Multiple rows update into a single query

Related Related

  1. 1

    DB2, optimize an update query

  2. 2

    Marking rows of table as duplicate if one column has duplicate values

  3. 3

    Check for duplicate rows in 2 columns before update

  4. 4

    MySQL query to update all "duplicate" rows except the latest one

  5. 5

    MySQL query to update all "duplicate" rows except the latest one

  6. 6

    How to update the same column for multiple rows in DB2

  7. 7

    Update duplicate rows

  8. 8

    Unable to Update rows of DataGridView from DB Query

  9. 9

    Query not updating the correct Rows

  10. 10

    Update duplicate rows except for one

  11. 11

    MySQL query returns duplicate rows

  12. 12

    Query to find duplicate rows in a table

  13. 13

    How to get row update count in a DB2 update query in node.js?

  14. 14

    MySQL ON DUPLICATE KEY UPDATE wth JOIN for multiple rows insert in single query

  15. 15

    Django admin: list not correct (duplicate rows)

  16. 16

    MySQL update query for duplicate entries

  17. 17

    mysql query to update duplicate entries

  18. 18

    Update Query For Duplicate Records Oracle

  19. 19

    PHP PDO MySQL Correct way to check if an update query succeeded when no rows are affected

  20. 20

    Is it possible from a DB2 (or any other sql) query to fetch rows selectively as shown below?

  21. 21

    Returning a default value when query does not return rows in DB2

  22. 22

    How to update exactly one record and select updated row in a single db2 query

  23. 23

    How to update exactly one record and select updated row in a single db2 query

  24. 24

    Marking duplicate values in new column

  25. 25

    Update table with duplicate rows in another table

  26. 26

    MySQL: Update all rows in 2 table matching results of another query

  27. 27

    sql server query for update rows which are multiple of 2

  28. 28

    linq query to update multiple rows

  29. 29

    Multiple rows update into a single query

HotTag

Archive