473,774 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing duplicates from query, but not from table

I've been searching for awhile now on how to remove duplicates from a
table within an Access db and have found plenty of articles on finding
or deleting duplicates. All I want to do is remove them from within an
SQL query - leaving one of the records behind of course.

I have a mailing list comprised of a union query that gets records from
two separate tables.
I want to be able to run a query that removes one (or more) of the
duplicated addresses within the query but doesn't make any
modifications to the table.

Please help! :)

Dec 15 '05 #1
16 4186
It doesn't really make sense to say you want to delete duplicate addresses
from a query without modifying a table. A query is just a way of displaying
what's in a table, so anything you delete via a query is deleted from the
table. If you want you could put the results of your unioin query into a new
table (make it a make table query), and then you could remove duplicates
from that table (via a query) without modifying the original tables.
hope that helped
-John

"tyrfboard" <ht*****@gmail. com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
I've been searching for awhile now on how to remove duplicates from a
table within an Access db and have found plenty of articles on finding
or deleting duplicates. All I want to do is remove them from within an
SQL query - leaving one of the records behind of course.

I have a mailing list comprised of a union query that gets records from
two separate tables.
I want to be able to run a query that removes one (or more) of the
duplicated addresses within the query but doesn't make any
modifications to the table.

Please help! :)

Dec 15 '05 #2

"tyrfboard" <ht*****@gmail. com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
I've been searching for awhile now on how to remove duplicates from a
table within an Access db and have found plenty of articles on finding
or deleting duplicates. All I want to do is remove them from within an
SQL query - leaving one of the records behind of course.

I have a mailing list comprised of a union query that gets records from
two separate tables.
I want to be able to run a query that removes one (or more) of the
duplicated addresses within the query but doesn't make any
modifications to the table.

Please help! :)


I'm not completely clear on what you are trying to do, but.. A UNION query
will, by default, eliminate duplicate records between the member queries.
If you wanted to include all records, regardless of duplicates, you would
need to use UNION ALL.

If you are getting duplicates from within the member queries, then what you
need is the DISTINCT qualifier.

SELECT DISTINCT
field1, field2, field3
FROM
table1
UNION
SELECT DISTINCT
field1, field2, field3
FROM
table2

This syntax should eliminate all of the duplicates from you query output.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.

Dec 15 '05 #3
Thank you for your replies.... let me try to explain what I'm doing and
maybe that will help me get the best of your expert advice.

For example: Lets say I have two tables with names, addresses, etc:
Personal table
Work table

I've got a Union query that merges the fields from Personal and Work
together into one mailing list.

However, there are people who belong on both the personal and work
lists - but I don't want to send mail to those individuals twice.

If each field in these records were exactly the same, then select
distinct would work beautifully. Problem is, the dups might be like
this:

FirstName | LastName | HomeNum | HomeStreet
---------------------------------------------
Jonah | Smith | 1983 | Dovecrest Lane (from work)
Jon | Smith | 1983 | Dovecrest (from personal)

So I would like to have a query that would deselect one of those lines
based on the LastName and HomeNum fields matching up. AND, if
possible, I'd like for the line that is kept to come from the Work
table as that is updated more often.

Dec 15 '05 #4
Oh!

Dec 15 '05 #5
Is the combination of LastName and HomeNum the criteria that would always
use to determine if the records were duplicates?

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
"tyrfboard" <ht*****@gmail. com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Thank you for your replies.... let me try to explain what I'm doing and
maybe that will help me get the best of your expert advice.

For example: Lets say I have two tables with names, addresses, etc:
Personal table
Work table

I've got a Union query that merges the fields from Personal and Work
together into one mailing list.

However, there are people who belong on both the personal and work
lists - but I don't want to send mail to those individuals twice.

If each field in these records were exactly the same, then select
distinct would work beautifully. Problem is, the dups might be like
this:

FirstName | LastName | HomeNum | HomeStreet
---------------------------------------------
Jonah | Smith | 1983 | Dovecrest Lane (from work)
Jon | Smith | 1983 | Dovecrest (from personal)

So I would like to have a query that would deselect one of those lines
based on the LastName and HomeNum fields matching up. AND, if
possible, I'd like for the line that is kept to come from the Work
table as that is updated more often.


Dec 15 '05 #6
In this case, yes.

Dec 15 '05 #7
I don't know what you mean by "In this case". It would be rather easy to
create a query that would do what you are asking for if that were the
criteria.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
"tyrfboard" <ht*****@gmail. com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
In this case, yes.


Dec 15 '05 #8
Note to all: This message has been posted to at least one other newsgroup.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
"tyrfboard" <ht*****@gmail. com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
I've been searching for awhile now on how to remove duplicates from a
table within an Access db and have found plenty of articles on finding
or deleting duplicates. All I want to do is remove them from within an
SQL query - leaving one of the records behind of course.

I have a mailing list comprised of a union query that gets records from
two separate tables.
I want to be able to run a query that removes one (or more) of the
duplicated addresses within the query but doesn't make any
modifications to the table.

Please help! :)


Dec 15 '05 #9
Randy,

I meant yes -- I said "in this case" as I might want to change the
criteria at some point.

Dec 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
17946
by: Rad | last post by:
I have a table . It has a nullable column called AccountNumber, which is of varchar type. The AccountNumber is alpha-numeric. I want to take data from this table and process it for my application. Before doing that I would like to filter out duplicate AccountNumbers. I get most of the duplicates filtered out by using this query: select * from customers where AccountNumber NOT IN (select AccountNumber from customers where AccountNumber...
4
3627
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for the app has a mixture of select boxes, list boxes and checkboxes. The form submits the page to processAIMR.asp and then does the inserting. I am using a loop to insert a new record for each checkbox checked or listbox entry selected. My...
2
1484
by: En | last post by:
Any ideas what to do for the best? I have a table that records some transaction data. Each entry in the table has an auto gen primary key / ID. Somewhere along the way there are 1000's of duplicate transactions been entered, however they are unique because they have different primary key / ID. Does anyone know the best way to remove the duplicates from the table but
3
4612
by: Tom Mitchell | last post by:
All: I'm stumped on a query. How do I find duplicates in a table where one of the duplicates has values is a certain field and the other doesn't. For example, I have the following table: tblItems ItemID ItemLabel
0
2585
by: makthar | last post by:
In your query use DISTINCT SELECT DISTINCT CITY FROM <tablename> WHERE STATE='<state name>'. This will bring only one of each city from the table. >-----Original Message----- >I'm getting a list of addresses from a database and binding them to a >datagrid. I have a dropdown list that allows the user
2
2686
by: sjlung | last post by:
I apologise if this is a trivial question but I have appended three tables in access and within this table, there are duplicate entries. I have tried to set my reference number for this table to be a primary key to ensure duplicates are no longer shown but this changes itself as soon as the tables are all appended together. I appreciate any help you can give me. Thanks alot.
4
6323
by: tcfin | last post by:
Hi, i have a problem to make a transtype from field XX varchar(20), example : 19 200 340,56 to field YY integer, required : 19200340
5
2013
by: tom.hepworth | last post by:
Hi I have a problem which I hope someone can help me with because I really don't even know where to start with it. I am using Access 2003. I have a delimited text file which contains about 200,000 lines. There are only 2 fields, Role and ID. The role field contains many duplicates, out of the 200,000 records I think there are only 16,000 unique roles. Role ID AB_F2S_COST_PLAN_CLK EE1
16
3519
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10040
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.