469,086 Members | 1,277 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,086 developers. It's quick & easy.

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!
Aug 20 '12 #1

✓ answered by Rabbit

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.

3 2609
Rabbit
12,516 Expert Mod 8TB
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.
Aug 21 '12 #2
That worked, thank you once more!
Aug 21 '12 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck!
Aug 21 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Omavlana | last post: by
2 posts views Thread by patrick beyries | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.