Access 2013 Duplicate Finder Subquery Issue

geospatial

Active Member
Joined
Sep 2, 2008
Messages
290
I currently have the following SQL code
SQL:
SELECT qryAllKeys.KeyTitle, qryAllKeys.employeeFirstName, qryAllKeys.employeeLastName, qryAllKeys.employeeMiddleInitial, qryAllKeys.keyNumber, qryAllKeys.serialNumber
FROM qryAllKeys
WHERE (((qryAllKeys.KeyTitle)=(SELECT [KeyTitle] FROM [qryAllKeys] As Tmp GROUP BY [KeyTitle] HAVING Count(*)>1 )))
ORDER BY qryAllKeys.KeyTitle;

It does work unless there is more than one set of duplicates and then I get the error: "At most one record can be returned by this subquery". I am not sure how to fix this issue in the SQL Code.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Does changing it to this help?

SQL:
SELECT qryAllKeys.KeyTitle, qryAllKeys.employeeFirstName, qryAllKeys.employeeLastName, qryAllKeys.employeeMiddleInitial, qryAllKeys.keyNumber, qryAllKeys.serialNumber
FROM qryAllKeys
WHERE (((qryAllKeys.KeyTitle) IN (SELECT [KeyTitle] FROM [qryAllKeys] As Tmp GROUP BY [KeyTitle] HAVING Count(*)>1 )))
ORDER BY qryAllKeys.KeyTitle;
 
Upvote 0
Sorry for the delayed response. Changing it to what you had fives me the error "Your query does not include the specified expression 'Count(*)>1 AND [keyNumber] & "_"[serialNumber]=' as part of an aggregated function. Is that because its a concatenated field? Can I not use that?
 
Upvote 0
Hi, Post your SQL now - the errors you report don't seem to match anything in the above queries really so would need to see exactly what you are doing.
 
Upvote 0
SQL:
SELECT qryAllKeys.KeyTitle, qryAllKeys.employeeFirstName, qryAllKeys.employeeLastName, qryAllKeys.employeeMiddleInitial, qryAllKeys.keyNumber, qryAllKeys.serialNumber
FROM qryAllKeys
WHERE (((qryAllKeys.KeyTitle) IN (SELECT [KeyTitle] FROM [qryAllKeys] As Tmp GROUP BY [KeyTitle] HAVING Count(*)>1 )))
ORDER BY qryAllKeys.KeyTitle;
 
Upvote 0
Your query works for me. Not sure what's going on. Weird thing is I don't even see this stuff in your query at all: 'Count(*)>1 AND [keyNumber] & "_"[serialNumber]='
 
Upvote 0
Your query works for me. Not sure what's going on. Weird thing is I don't even see this stuff in your query at all: 'Count(*)>1 AND [keyNumber] & "_"[serialNumber]='
The only thing I can think of is that the the AND [keyNumber]&"_"[serialNumber]=' is the concatenated formula for [keyTitle]
 
Upvote 0
The only thing I can think of is that the the AND [keyNumber]&"_"[serialNumber]=' is the concatenated formula for [keyTitle]
Can you post that query, too? The concatenation formula doesn't really look right, but it'd be best to see it in the source query.
 
Upvote 0
I suppose it might help if you post the query for qryAllKeys too.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top