SQL Server Performance

Can anyone plz solve this query

Discussion in 'SQL Server 2008 Questions [Archive Only - Closed]' started by vishu1484, Jul 28, 2009.

  1. vishu1484 New Member

    Hi,
    There is one table name as master with record as below.

    A/c No Dept
    1 A
    2 B
    3 C
    4 D
    5 A
    6 D
    7 A
    8 B
    Now i want the record which is duplicates in it.(only duplicates record should display)
    Like in above table A, D and B are duplicates so that only record should display with as many times they are present in table.
    Thanks,
    Vishal
  2. FrankKalis Moderator

    Welcome to the forum!
    If I understand you correctly, you're looking for something like
    SELECT Dept
    FROM table
    GROUP BY Dept
    HAVING COUNT(*) > 1
    Is this a homework question? [;)]
  3. Madhivanan Moderator

    <<
    Like in above table A, D and B are duplicates so that only record should display with as many times they are present in table.
    >>
    Not sure what you meant
    Do you want to list it as many times as there are data?
  4. vishu1484 New Member

  5. Madhivanan Moderator

    [quote user="vishu1484"]
    Yes
    [/quote]
    If this answer to my question
    SELECT t1.Dept
    FROM table as t1inner join
    (
    SELECT Dept
    FROM table GROUP BY Dept
    HAVING COUNT(*) > 1
    ) as t2 on t1.Dept=t2.Dept
  6. vishu1484 New Member

    Hey thanks a lot it's perfect...
  7. Madhivanan Moderator

    [quote user="vishu1484"]
    Hey thanks a lot it's perfect...
    [/quote]
    You are welcome [:)]

Share This Page