473,413 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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 2761
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

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

Similar topics

3
by: Omavlana | last post by:
Hi, How to get the value as 0 insted of NULL if there is no data found in the database for a particular column in the following Access query. select col1, col2 from tab1; If there are null...
2
by: Mattyw | last post by:
Hi I have a sqlcommand that returns all the rows in a column and then pass that to a datareader. I am new to VS.Net and so far I can only return the first row in the first column using ...
8
by: s_wadhwa | last post by:
SELECT DISTINCTROW "01C" AS dummy, Buildings.BuildingNumber, UCASE(Buildings.BuildingName) AS BuildingName, Buildings.MasterPlanCode, Buildings.UniformBuildingCode,...
2
by: patrick beyries | last post by:
fair Warning - Admittedly I'm far from an access expert, but I'm not a beginner either. I want to split a value into multiple parts as delimited by a character - all as part of a query. For...
4
by: ShastriX | last post by:
Getting a weird error while trying out a query from Access 2003 on a SQL Server 2005 table. Want to compute the amount of leave taken by an emp during the year. Since an emp might be off for...
5
by: redstamp | last post by:
Try as I might I cannot find a way to write an access query to return a result set with the records from my database WITHOUT a certain set of values within a field. To explain, I have a table of...
2
by: xdeanda | last post by:
SQL Syntax: How do I make a query prompt me for a column's criteria? In other words, let's say I have a table with many rows that represent computer parts, and I have a column for the system ID. I...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
4
by: Bobby Edward | last post by:
I have an xsd dataset. I created a simple query called GetDataByUserId. I can preview the data fine! I created a very simple BLL function that calls it and returns a datatable. When I run...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.