Access: query to remove rows with repeated values in a column?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yaridovich
    New Member
    • Aug 2012
    • 11

    Access: query to remove rows with repeated values in a column?

    Hello everyone,

    I'm trying to come up with a query that removes rows where a certain column has the same value (for instance, the column's value is the same in rows #503, #677 and #1020).
    There are two catches:
    - I can't specify the value (or values) to be checked for repetition, the query has to check for any repeated value;
    - I can't also specify the number of repetitions, the minimum is 2 but there's no maximum.

    I want to remove all repeated rows, except for the first one.
    Also, it can't be just a View, I have to actually remove these rows from the table.

    I've been thinking, but can't come up with anything. "SQL DISTINCT *" doesn't help because I have to look for repetitions only in this specific column. Perhaps some way of using "SQL DISTINCT [ColumnName]", but I've been unable to form the whole query.

    I've also googled about this, but none of the results helped me (either they involved 2 columns, used Distinct in a way that doesn't help my case, used Views or involved 2 tables).

    All help is appreciated. Thanks in advance!
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You'll need a column with a unique id. Create one if you don't have one. Create a query that returns the minimum id grouped by the field you want to be unique. Create another query that aggregates on the field and returns only those has more than 1 row. Join all of it back to the original table to return the ids that need to be deleted.

    Comment

    • Yaridovich
      New Member
      • Aug 2012
      • 11

      #3
      That worked, thank you once more!

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Not a problem, good luck!

        Comment

        Working...