Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unique values in two fields in query

3 views
Skip to first unread message

Colin Hayes

unread,
Jan 13, 2013, 7:13:46 PM1/13/13
to

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

unread,
Jan 15, 2013, 12:28:18 PM1/15/13
to
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$ALA620...@chayes.demon.co.uk...
0 new messages