banner
RustyNail

RustyNail

coder. 【blog】https://rustynail.me 【nostr】wss://ts.relays.world/ wss://relays.world/nostr

Remove duplicates in MySQL

Direct code

SELECT
    id,
    koto 
FROM
    hitokoto 
WHERE
    koto IN (SELECT t1.koto FROM hitokoto t1 GROUP BY t1.koto HAVING COUNT(1) > 1) 
    AND id NOT IN (SELECT MIN(id) FROM hitokoto t1 GROUP BY t1.koto HAVING COUNT(1) > 1)

Remove the same koto and leave the smallest id.

Find all rows that are the same, find the smallest ones, then not in.

Seems a bit slow.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.