Hi.
As Van mentioned, your table is not designed correctly, because it
includes
two entities, persons and marital relationships, instead of just one
entity.
This table should be separated into two tables, a process called
normalization. However, after reading in your previous post about how
long
it took you to get this far, I suspect that this process isn't going to
happen any time soon.
You've got entries in your table that aren't really duplicates, but they
are
logically equivalent to other entries in the table, such as "Jim & Jane
Jones" and "Jane & Jim Jones." You can separate these out, but the
queries
are going to be a bit ugly.
You'll need a single field primary key for these queries, so if you don't
already have one, you can add an AutoNumber as the primary key
temporarily to
make these queries work. Before you alter the table though, make a
backup of
your table, just in case something goes wrong. The code I've written
assumes
that the primary key is named ID, so if yours isn't the same, then you'll
need to replace ID in the code with your primary key's column name.
You're going to create two queries. The first one is going to separate
by
last name and show each couple's names side by side, first with one name
on
the left side in one column, then with the other name on the left side in
the
next column. For example, JohnMary and MaryJohn. The second query will
compare these pairs of names in one column to determine whether there are
any
matching duplicates in the other column but in different rows. Then it
will
pick only the first pair found, no matter how many other duplicates or
near
duplicates are stored in the table and use that record in your UNION
query.
Create a new query and open it in SQL View. Copy and paste the following
into the SQL View pane:
SELECT ID, DCC.[LAST NAME],
(Called & Spouse) AS Pair,
(Spouse & Called) AS Swap
FROM DCC INNER JOIN
(SELECT [LAST NAME]
FROM DCC
GROUP BY [LAST NAME]
HAVING (COUNT([LAST NAME]) > 1)) AS Dups
ON DCC.[LAST NAME] = Dups.[LAST NAME];
Save this query as qryFindNearDuplicates. Create a new query and open it
in
SQL View. Copy and paste the following into the SQL View pane:
SELECT [BIRTH DA] AS EDate,
[CALLED] & " " & [LAST NAME] AS who
FROM DCC
WHERE [BIRTH DA] IS NOT NULL
UNION ALL
SELECT [WED DA], (Called & " & " & Spouse &
" " & [LAST NAME]) AS Couple
FROM (SELECT IIf((P.ID>S.ID),P.ID,S.ID) AS Cut
FROM qryFindNearDuplicates AS P INNER JOIN
qryFindNearDuplicates AS S ON (P.Pair=S.Swap)
AND (P.[LAST NAME]=S.[LAST NAME])) AS Q
RIGHT JOIN DCC ON Q.Cut = DCC.ID
WHERE (ISNULL(Cut) = TRUE) AND [WED DA] IS NOT NULL
ORDER BY 1;
Save this query and name it anything you want. Hopefully, I've copied
and
pasted these correctly from my example and your query listed in another
post.
(If not and you can't get them to run correctly, please post back.) Run
the
second query to see your records in the correct order and without
duplicate
wedding dates.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
:
I have a union query that has birth dates and wedding dates.
Birthdates are fine.
The table has Last Name, Called, Spouse and Wed Da
SELECT [WED DA], [CALLED] & " & " & [SPOUSE] & " " & [LAST NAME] FROM
DCC
Where [WED DA] IS NOT NULL
ORDER BY EDate
The query shows 9 23 1934 Jim & Jane Jones
and 9 23 1934 Jane & Jim Jones
How do I get only one entry for each couple?
Thanks