Removing duplicated entries from database

Add-on:Linking
Question:Removing duplicated entries from database
Answer:

On older versions of Linking, Linking creates duplicated entries on the LINKS table. This issue has been rectified on Linking 3.0.12. However, older duplicated entries will still remain on the database. Therefore, you'll need to manually remove the duplicated entries from the database. Here's an example query which you can use to remove the duplicated entries:

DROP TEMPORARY TABLE IF EXISTS link_min_ids;
  
CREATE TEMPORARY TABLE link_ids_to_delete (INDEX(linkid)) ( 
SELECT Linkid from
    LINKS t1
where
    exists( 
        select 
            'x'
        from
            LINKS t2
        where
                    t2.CONTENTID = t1.CONTENTID
                and t2.DESTPAGETITLE = t1.DESTPAGETITLE
                and t2.DESTSPACEKEY = t1.DESTSPACEKEY
                and t2.LINKID < t1.LINKID
    )
);

DELETE l from link_ids_to_delete lm, links l WHERE l.linkid = lm.linkid;