
Peter,
What do you need help with exactly? Please explain in detail how we can assist you.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
DELETE FROM PICKING WHERE([Alternate User ID (Locus)], [Date Of Shift]) IN (SELECT[Alternate User ID (Locus)], [Date Of Shift]FROMPICKINGGROUP BY[Alternate User ID (Locus)], [Date Of Shift]HAVINGCOUNT(*) > 1)AND(SELECT COUNT(*)FROM PICKING AS P2WHERE P2.[Alternate User ID (Locus)] = PICKING.[Alternate User ID (Locus)]AND P2.[Date Of Shift] = PICKING.[Date Of Shift]) > 1;
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Peter,
What do you need help with exactly? Please explain in detail how we can assist you.
What happens when you open that query (and it's SQL in a query, not a "script")?
An error is raised? If so, show us the error message itself.
The wrong results are returned? If so what do you expect and what is returned?
No results at all?
Thank you.
You are referencing two columns in the WHERE clause, and returning the same two columns in the first subquery. As you are applying the IN operator to the subquery, however, this expects a single column as both operands. Instead of using the IN operator use the EXISTS predicate and correlate the subquery with the outer query:
DELETE *
FROM PICKING AS P1
WHERE EXISTS
(SELECT
[Alternate User ID (Locus)], [Date Of Shift]
FROM
PICKING AS P2
WHERE
P2.[Alternate User ID (Locus)] = P1.[Alternate User ID (Locus)]
AND P2.[Date Of Shift] = P1.[Date Of Shift]
GROUP BY
[Alternate User ID (Locus)], [Date Of Shift]
HAVING
COUNT(*) > 1);
PS: You do realise that what you are attempting will delete all rows which are duplicated on the two columns in question? Is this what is intended? For examples of how to delete all bar one of duplicate rows see DeleteDemo.zip in my Dropbox public databases folder at:
This little demo file illustrates two queries which will delete all duplicates bar one, in one case using the primary key to determine which row to retain, in the other using the value of a non-key column.