Discussion:
Unique values in two fields in query
(too old to reply)
Colin Hayes
2013-01-14 00:13:46 UTC
Permalink
Hi All

In my db I have some duplicated values in two fields.

I need to make my query match these and only show records which have no
duplication in these fields. How should I amend my query to do this?

The Unique Records / Unique Values switches seem to affect the whole
query and not just the two fields I want to match.

Grateful for any advice.



Best Wishes
Douglas J Steele
2013-01-15 17:28:18 UTC
Permalink
Create a subquery that returns those combinations that appear only once:

SELECT Field1, Field2
FROM MyTable
GROUP BY Field1, Field2
HAVING Count(*) = 1

Join your table to that subquery:

SELECT Id, Field1, Field2, Field3
FROM MyTable
INNER JOIN
(SELECT Field1, Field2
FROM MyTable
GROUP BY Field1, Field2
HAVING Count(*) = 1) As Subq
ON MyTable.Field1 = Subq.Field1
AND MyTable.Field2 = Subq.Field2

"Colin Hayes" wrote in message news:SH4$***@chayes.demon.co.uk...


Hi All

In my db I have some duplicated values in two fields.

I need to make my query match these and only show records which have no
duplication in these fields. How should I amend my query to do this?

The Unique Records / Unique Values switches seem to affect the whole
query and not just the two fields I want to match.

Grateful for any advice.



Best Wishes

Loading...