How to filter duplicate entries in mysql?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    How to filter duplicate entries in mysql?

    hey guys,

    i'm stuck with finding a sql statement for filtering out duplicate entry

    i got like thousands of entry but i would like to put a filter on so i can see all the duplicate entries

    any idea how?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What's your table structure? Do you have at least one unique column in the table?
    If you have it then the general structure of your query would be

    [CODE=mysql]select * from tableName where id not in (
    select min(id) from tableName group by col1, col2, ...)[/CODE]
    This will give all the values with duplicate entries in col1, col2, ... but with different ids. It will also however not show the row with the minimum id.

    Comment

    • poolboi
      New Member
      • Jan 2008
      • 170

      #3
      Originally posted by r035198x
      What's your table structure? Do you have at least one unique column in the table?
      If you have it then the general structure of your query would be

      [CODE=mysql]select * from tableName where id not in (
      select min(id) from tableName group by col1, col2, ...)[/CODE]
      This will give all the values with duplicate entries in col1, col2, ... but with different ids. It will also however not show the row with the minimum id.
      hm...u mean a primary key?
      if so yeah i do have a unique column in my table

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by poolboi
        hm...u mean a primary key?
        if so yeah i do have a unique column in my table
        Then substitute id with your key column and col1, col2, ... with the columns where the duplicated values are. As I said above it should give you all the duplicates omitting the row with the lowest id.

        Comment

        Working...