Find duplicates with condition (1 Viewer)

alex44

Registered User.
Local time
Today, 07:25
Joined
Aug 29, 2013
Messages
14
Hello all,

I'm struggling to write the query bellow. Any suggestion are appreciated.
(Using Access 2013)

Sudo Code:

SELECT * FROM MYTABLE
WHERE COLUMN-A HAS COUNT > 1
AND COLUMN-B IS THE SAME

In other words, find the duplicates that have the same value for column-b.

Thanks!

Alex
 

jdraw

Super Moderator
Staff member
Local time
Today, 08:25
Joined
Jan 23, 2006
Messages
15,378
Access won't like the "-" character.
What does this mean
COLUMN-B IS THE SAME

Suggest you give a sample with data and the condition involved, and what the expected results should be --again using your sample data.
 

alex44

Registered User.
Local time
Today, 07:25
Joined
Aug 29, 2013
Messages
14
Thank you for your reply. I will try to clarify.

For the following sample data set:


NUMBER | NAME
=========================
11111 | Red
-------------------------
11111 | Red
-------------------------
33333 | Blue
-------------------------
33333 | Green
-------------------------
22222 | White
-------------------------


I would like a query that returns the first two records.
In other words, there is a duplicate “NUMBER” and they share the same “NAME”. The third and fourth records would not be returned because, although they share a duplicate “NUMBER” they do NOT have the same “NAME”. The last record (22222) would also not be returned because there is no duplicate “NUMBER”.

Again, thank you for your reply. Hopefully this clarifies things a bit.

Alex
 

jdraw

Super Moderator
Staff member
Local time
Today, 08:25
Joined
Jan 23, 2006
Messages
15,378
I put your data into a table called Numname. Then used the built-in query wizard to find duplicates.

Code:
SELECT Numname.[NUMBER], Numname.[NAME] 
FROM Numname
WHERE (((Numname.[NUMBER]) In 
 (SELECT [NUMBER] FROM [Numname] As Tmp 
GROUP BY [NUMBER],[NAME] HAVING Count(*)>1  And [NAME] = [Numname].[NAME])))
ORDER BY Numname.[NUMBER], Numname.[NAME];
 

jdraw

Super Moderator
Staff member
Local time
Today, 08:25
Joined
Jan 23, 2006
Messages
15,378
Glad it was helpful.
Access has some reserved words -- including Number and Name -you might want to review the list. It's often easier to add a prefix to a term/variable to make them meaning to you. People refer to this approach as Hungarian notation and generally use some parts or modification that suits their purposes. This lessens the issue of using reserved words.
 

Users who are viewing this thread

Top Bottom