Skip to main content
December 20, 2022
Question

Duplicate entries in database table

  • December 20, 2022
  • 4 replies
  • 0 views

Hi,

I have a situation where there is a need to identify the duplicate entries in a database table and delete the duplicate rows. How can I do this?

    4 replies

    December 20, 2022

    You can use GROUP BY and HAVING clause, or maybe do some data locking to prevent duplicates.

    community.appian.com/.../data-locking-strategies

    prafuls972
    December 20, 2022

    DELETE 
        FROM
        employee
    WHERE
        id IN(
        SELECT
            id
        FROM
            (
            SELECT
                id,
                RANK() OVER(
                PARTITION BY firstname,
                middlename,
                lastname
            ORDER BY
                id
            ) my_rank
        FROM
            employee) AS c
            WHERE
                c.my_rank > 1
        );

    you can use this MySQL code to delete the duplicate row in my employee table I have 4 columns id(PrimaryKey),firstname,middlename,lastname. Above mention query will delete all the duplicate rows but will keep one entry of each unique row.

    Note this query can partition on the basis of one column or multiple columns or all the columns depending on your requirement change the table name and column names used in the partition. if you want to remove all the duplicates then no need to apply where clause c.my_rank>1

    December 21, 2022

    Hi Praful, thanks for ur reply. Where in Appian do i use this SQL query?

    prafuls972
    December 21, 2022

    You can use this query in stored procedure which can be triggered from the process model.