on this thread i had a question which was successfully answered.
searching for filtered duplicates in access query
Now i have a second problem. Maybe someone can help me.
I have a query which looks like this:
query A_Gravur:
SP1 | SP2 | SP3 64 | CB75000 | 3 64 | empty | D 70 | CB70010 | 1 70 | CB70010 | 1 119 | CB70050 | 5 119 | empty | D 165 | S15002 | Schalter 165 | S15002 | Schalter 194 | R70034 | Poti 194 | R10023 | Potentiometer 196 | S10063 | Schalter 196 | S10063 | Schalter 197 | S10063 | Schalter 198 | S10070 | 3 199 | CB75000 | 5
This query is filtered by another query to check for duplicates. The final result looks like this:
Result:
SP1 | SP2 | SP3
194 | R70034 | Poti 470k
194 | R10023 | Potentiometer
196 | S10063 | Schalter
197 | S10063 | Schalter
64 | CB75000 | 3
199 | CB75000 | 5
and the SQL Code for this looks like this:
SELECT SP1, SP2, SP3
FROM A_Gravur
WHERE (SP1 IN
(SELECT SP1
FROM A_Gravur
WHERE SP3<>'D'
GROUP BY SP1
HAVING COUNT(*)>1)
OR SP2 IN
(SELECT SP2
FROM A_Gravur
WHERE SP3<>'D'
GROUP BY SP2
HAVING COUNT(*)>1))
AND CONCAT(CAST(SP1 AS CHAR),SP2,SP3) NOT IN
(SELECT CONCAT(CAST(SP1 AS CHAR),SP2,SP3)
FROM A_Gravur
WHERE SP3 <> 'D'
GROUP BY CONCAT(CAST(SP1 AS CHAR),SP2,SP3)
HAVING COUNT(*)>1)
AND SP3<>'D'
ORDER BY SP1, SP2;
SO NOW MY NEW PROBLEM:
I added 2 new columns to the query A_Gravur (SP4 and SP5) and did the duplicate search
SP1 | SP2 | SP3 | SP4 | SP5 |
194 | R70034 | Poti 470k |123546 |88859
194 | R10023 | Potentiometer |88859 |
196 | S10063 | Schalter |7773 |
197 | S10063 | Schalter |99992 |
64 | CB75000 | 3 |177777 |
199 | CB75000 | 5 |99999 |
Explain: in SP4 there are always values (Materialnumber). Now when i'm searching for duplicates it should only find this result:
SP1 | SP2 | SP3 | SP4 | SP5 |
196 | S10063 | Schalter |7773 |
197 | S10063 | Schalter |99992 |
64 | CB75000 | 3 |177777 |
199 | CB75000 | 5 |99999 |
because the Number in SP5 (88859) is also in SP4 (88859) and SP1 is in both records the same number (194)
but if it looks like this then the result is correct
SP1 | SP2 | SP3 | SP4 | SP5 |
194 | R70034 | Poti 470k |123546 |0000001
194 | R10023 | Potentiometer |88859 |
196 | S10063 | Schalter |7773 |
197 | S10063 | Schalter |99992 |
64 | CB75000 | 3 |177777 |
199 | CB75000 | 5 |99999 |
Thank you for your help!!