Get Duplicate Data

  • I have the following query to get the duplicate AccountNames;

    SELECT AccountName

    FROM Account

    GROUP BY AccountName

    HAVING COUNT(*) > 1

    How do I also retrieve the AccountID as well as its duplicate AccountName as well?

    Example;

    AccountID        AccountName

    1                     ABC

    2                     ABC

    3                     XYZ

    4                     XYZ


    Kindest Regards,

  • Try:

    select a.AccountID, a.AccountName, b.Duplicated

    From Account a

    inner join (

    select accountname, count(*) as duplicated

    from account group by accountname

    having count(*) > 1) b on a.accountname = b.accountname

  • Thanks wz700. Is the JOIN what's called a Derived Table?


    Kindest Regards,

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply