Up against a SQL question that is difficult to code. Any help is greatly appreciated.
General example. I want to select duplicate records that have the same INVOICE NUMBER with one or more occurences with an INVOICE AMOUNT = $10.00.
DATABASE = TEST
TABLE = INVOICES
INVOICE NUMBER INVOICE AMOUNT
123 $20.00
234 $50.00
123 $10.00
657 $11.00
123 $40.00
234 $20.00
I can select duplicates by INVOICE NUMBER using the following:
SELECT [INVOICE NUMBER],[INVOICE AMOUNT]
FROM [TEST].[dbo].[INVOICES]
WHERE ((([INVOICES].[INVOICE NUMBER]) In
(SELECT [INVOICE NUMBER]
FROM [test].[dbo].[INVOICES] AS Tmp
GROUP BY [INVOICE NUMBER]
HAVING Count(*)>1)));
Resulting set is:
123 $20.00
234 $50.00
123 $10.00
123 $40.00
234 $20.00
But, I only want to select those duplicates that have one or more occurences where the INVOICE AMOUNT = $10.00.
Desired set would be:
123 $20.00
123 $10.00
123 $40.00
Can you help??? - THANKS!!!!!