Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts

    search for duplicates

    I have a table w/ id, first name, last name, score.

    I want to do a search of all people who have are in the table more than once.

    ie.

    select * from table_1 where (first_name+last_name comes up more than twice.)

    thanks in advance,

    Tony
    ---------
    Client / Server Side Programmer II

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Two ways to do it...Join the table with itself... just make sure you exclude the rows that match IDs (because they're the same row).

    Code:
    SELECT t1.ID, t2.ID
    FROM table1 as t1
    JOIN table1 as t2
    ON t1.first_name = t2.first_name
    AND t1.last_name = t2.last_name
    WHERE t1.ID <> t2.ID
    Or, do a GROUP BY last_name, first_name HAVING count(*) > 1 (You won't be able to select the IDs this way).

    Code:
    SELECT last_name, first_name, count(*)
    ORDER BY 3 desc
    GROUP BY last_name, first_name
    HAVING count(*) > 1

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts
    thank you !!
    ---------
    Client / Server Side Programmer II


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •