B
Bob
running access 2000; I have a contacts table with name address phone
etc...
I'm trying to make a "find duplicates" query work, and am failing.
When I try to execute, i get an error message similiar to: "tried to
execute a query...expression...part of an aggregate function"
Here's the concept of what I want to do:
I'm looking for duplicate names. If I do JUST that - no problem. I get
a list of names that match one another; some of the names have null
addresses, some don't.
Here's what I want to add to this query:
If both of the records with a duplicated name, has a non-null address
field, AND those addresses do not match one another - then this isn't
REALLY a duplicate, and I don't want to see either record.
Here's how I've attempted to do this:
SELECT T_contacts.contact_id, T_contacts.last_name,
T_contacts.first_name, T_contacts.addr
FROM T_contacts
WHERE
(
(Q_patients.last_name)
In (
SELECT [last_name] FROM [T_contacts] As Tmp GROUP BY [last_name],
[first_name]
HAVING Count(*)>1 And [first_name] = [T_contacts].[first_name]
AND
( ([addr] <> '') and ([T_contacts].[addr] <> '') and [addr] =
[T_contacts].[addr] )
)
);
Could someone help me understand what the problem is with this
statement?
Or - is there a better way to do what I want?
TIA - Bob
etc...
I'm trying to make a "find duplicates" query work, and am failing.
When I try to execute, i get an error message similiar to: "tried to
execute a query...expression...part of an aggregate function"
Here's the concept of what I want to do:
I'm looking for duplicate names. If I do JUST that - no problem. I get
a list of names that match one another; some of the names have null
addresses, some don't.
Here's what I want to add to this query:
If both of the records with a duplicated name, has a non-null address
field, AND those addresses do not match one another - then this isn't
REALLY a duplicate, and I don't want to see either record.
Here's how I've attempted to do this:
SELECT T_contacts.contact_id, T_contacts.last_name,
T_contacts.first_name, T_contacts.addr
FROM T_contacts
WHERE
(
(Q_patients.last_name)
In (
SELECT [last_name] FROM [T_contacts] As Tmp GROUP BY [last_name],
[first_name]
HAVING Count(*)>1 And [first_name] = [T_contacts].[first_name]
AND
( ([addr] <> '') and ([T_contacts].[addr] <> '') and [addr] =
[T_contacts].[addr] )
)
);
Could someone help me understand what the problem is with this
statement?
Or - is there a better way to do what I want?
TIA - Bob