0

I'd like to query in MS Access for duplicate values in column I, but then do a secondary check to make sure A and B exists in column II for the duplicate.

In other words, column I would match duplicate values, column II would make sure values are different (within the subset, making 222 drop out of result).

+--------+---------+
|    I   |    II   |  
+--------+---------+
|   111  |    A    |  
--------------------
|   111  |    B    |   
--------------------
|   222  |    A    |  
--------------------
|   222  |    A    | 
+------------------+

Thanks in advance for your help.

1 Answer 1

0

You can simply use DISTINCT keyword for this purpose.

select distinct colI, colII
from table1;

Which will produce the below result

+--------+---------+
|    I   |    II   |  
+--------+---------+
|   111  |    A    |  
--------------------
|   111  |    B    |   
--------------------
|   222  |    A    |  
--------------------

If you want rows for only 111 then you can do

select colI, colII
from 
(
select colI, colII, 
Max(colII) as maxcolII,
Min(colII) as mincolII
from tabl1
group by colI
) tab
where maxcolII <> mincolII
5
  • Thank you, but access SQL does not support Count(Distinct col) Nov 14, 2014 at 21:25
  • @userinneedfriendindeed, you added SQL Server tag and so the answer was intended for it. check edited answer and try now.
    – Rahul
    Nov 14, 2014 at 21:41
  • @Rahul your second query is not working Column 'tabl1.colII' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    – Dgan
    Nov 26, 2014 at 4:44
  • @Ganesh_Devlekar, that's cause the other column is not part of group by but present in select list. Change the group-by to group by colI, colII
    – Rahul
    Nov 26, 2014 at 4:48
  • @Rahul as you said If you want rows for only 111 then you can do then it returns 0 rows
    – Dgan
    Nov 26, 2014 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.