By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,468 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Find Duplicates Query

P: n/a
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
ItemLat
ItemLong
(many other fields)

I want to return all the fields of all the records where there are two
or more identical ItemLabels, but only where ItemLat and ItemLong are
not null in one record and null in the other record(s).

Thanks

Tom
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
1. Open the database window to tables, right click on TblItems and copy.
2. Move the cursor to a blank area, right click and paste. Name the copy
TblItemsLatLongNull.
3. Create a query based on TblItems and set the criteria of ItemLat and
ItemLong to Is Not Null.
4. Create a query based on TblItemsLatLongNull and set the criteria of ItemLat
and ItemLong to Is Null.
5. Create a third query and include both queries in 3 and 4.
6. Join the ItemLabel field in both queries.
7. Run the query.

The join on ItemLabel will cause the query to return all records with duplicate
ItemLabel. Since the first query contains only records where ItemLat and
ItemLong are not null and the second query contains records where they are null,
the third query returns matching records where ItemLat and ItemLong are not null
in at least one of the matching records and null in one or more of the other
matching records.
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Tom Mitchell" <rt*****@swbell.net> wrote in message
news:70*************************@posting.google.co m...
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
ItemLat
ItemLong
(many other fields)

I want to return all the fields of all the records where there are two
or more identical ItemLabels, but only where ItemLat and ItemLong are
not null in one record and null in the other record(s).

Thanks

Tom

Nov 12 '05 #2

P: n/a
Thanks for the reply, but I don't think this is quite what I want.

Your approach returns duplicate fields - e.g. if there is an ItemColor
field then I will get a TblItems.ItemColor and a
TblItemsLatLongNull.ItemColor in the same record.

What I want is to get two records one with complete data from TblItems
and the other with complete data from TblItemsLatLongNull.

I've had a go at it by making a qryItemsLatLongNotNull and returning
only the ItemLabel, then making another query that links that
ItemLabel back to tblItems.ItemLabel. The problem with that is that I
get records back where the only record is one with no duplicates.

Any other suggestions are gratefully accepted.

Thanks

Tom
"PC Datasheet" <sp**@nospam.spam> wrote in message news:<yU******************@newsread1.news.atl.eart hlink.net>...
1. Open the database window to tables, right click on TblItems and copy.
2. Move the cursor to a blank area, right click and paste. Name the copy
TblItemsLatLongNull.
3. Create a query based on TblItems and set the criteria of ItemLat and
ItemLong to Is Not Null.
4. Create a query based on TblItemsLatLongNull and set the criteria of ItemLat
and ItemLong to Is Null.
5. Create a third query and include both queries in 3 and 4.
6. Join the ItemLabel field in both queries.
7. Run the query.

The join on ItemLabel will cause the query to return all records with duplicate
ItemLabel. Since the first query contains only records where ItemLat and
ItemLong are not null and the second query contains records where they are null,
the third query returns matching records where ItemLat and ItemLong are not null
in at least one of the matching records and null in one or more of the other
matching records.
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Tom Mitchell" <rt*****@swbell.net> wrote in message
news:70*************************@posting.google.co m...
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
ItemLat
ItemLong
(many other fields)

I want to return all the fields of all the records where there are two
or more identical ItemLabels, but only where ItemLat and ItemLong are
not null in one record and null in the other record(s).

Thanks

Tom

Nov 12 '05 #3

P: n/a
All:

Just to follow-up I think I have this solved.

I created one query that returns ItemLabel for just those with
non-null Latitudes (qryNoNull). Another query (qryNull) returning
ItemLabel for just those with null Latitudes. A third query
(qryCount) that returns the ItemLabel and a count of the number of
records with that ItemLabel.

A fourth query (qryCountDetail) then joining the results of qryCount
to tblItem (the underlying table) returning all the fields for only
those labels that have a count >=2. And finally a fifth query joining
qryCountDetail to qryNull and qryNoNull on ItemLabel and returning all
the fields in qryCountDetail.

Not very elegant, but it gets the job done.

Thanks - especially to you PCDatasheet for answering the first time
around.

Tom
"Tom Mitchell" <rt*****@swbell.net> wrote in message
news:70*************************@posting.google.co m...
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
ItemLat
ItemLong
(many other fields)

I want to return all the fields of all the records where there are two
or more identical ItemLabels, but only where ItemLat and ItemLong are
not null in one record and null in the other record(s).

Thanks

Tom

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.