当前位置:网站首页>SQL filter query duplicate columns

SQL filter query duplicate columns

2020-11-09 22:26:00 Game life

id_cardxx by table;id,id_card,phone Are fields

-- Show repeating Columns select * from Table name where Name in (select Name from Table name group by Name having COUNT(*)>1) order by Name

select * from file_selection where mash in (select mash from file_selection group by mash having COUNT(*)>1) order by mash

-- Query duplicate data but exclude Minimum id MIN( id )

SELECT *
    FROM
        id_cardxx c 
    WHERE
        EXISTS (
        SELECT
            a.id 
        FROM
            id_cardxx a,
            ( SELECT id_card, MIN( id ) AS rid FROM id_cardxx GROUP BY id_card HAVING count( 1 ) > 1 ) b 
        WHERE
            a.id_card = b.id_card 
            AND a.id != b.rid 
            AND c.id = a.id 
        ) 
        AND id > 8071 
        AND phone IS NULL 
    ORDER BY
        c.id_card;

-- To modify, you need to query the data as a new table once And

UPDATE id_cardxx 
set  Modify fields  = 'xxxx'
WHERE id in ( SELECT....end ) as xx1

 -- complete sql

UPDATE id_cardxx 
set source = 'xxxx'
WHERE id in (
        SELECT xx1.id FROM
        (
        SELECT id
            FROM
                id_cardxx c 
            WHERE
                EXISTS (
                SELECT
                    a.id 
                FROM
                    id_cardxx a,
                    ( SELECT id_card, MIN( id ) AS rid FROM id_cardxx GROUP BY id_card HAVING count( 1 ) > 1 ) b 
                WHERE
                    a.id_card = b.id_card 
                    AND a.id != b.rid 
                    AND c.id = a.id 
                ) 
                AND id > 8071 
                AND phone IS NULL 
        ) as xx1
)

 

版权声明
本文为[Game life]所创,转载请带上原文链接,感谢