Reputation: 172
I'm trying to filter the query based on the result of 1 column, and I don't want any duplicate. This is the query:
SELECT T1."CardName",
T0."Dscription",
T0."DocEntry",
T1."FolioNum",
T1."DocTotal",
T1."DocDate",
T2."SeriesName",
T1."Series"
FROM INV1 T0
INNER JOIN OINV T1 ON T0."DocEntry" = T1."DocEntry"
INNER JOIN NNM1 T2 ON T1."Series" = T2."Series"
WHERE T1."DocTotal" > 1000 AND
T0."DocDate" between [%1] and [%2]
I want everything T0."DocEntry"
to be my unique result, I tried distinct, but that doesn't work in the way I want.
+--------------+-----------------+---------------+-----+
| T1."CardName"| T0."Dscription" | T0."DocEntry" | ... |
+--------------+-----------------+---------------+-----+
| name 1 | product1 | 3111 | |
| name 1 | product2 | 3111 | |
| name 2 | product3 | 3222 | |
| name 2 | product4 | 3222 | |
+--------------+-----------------+---------------+-----+
What I need
+--------------+-----------------+---------------+-----+
| T1."CardName"| T0."Dscription" | T0."DocEntry" | ... |
+--------------+-----------------+---------------+-----+
| name 1 | product1 | 3111 | |
| name 2 | product3 | 3222 | |
+--------------+-----------------+---------------+-----+
Hope can you help me.
Upvotes: 1
Views: 4395
Reputation: 591
You would use the distinct feature in SQL to eliminate these duplicate rows. Just give it a quick Google search and you should be okay.
SELECT DISTINCT SALARY FROM CUSTOMERS
ORDER BY SALARY;
Quick example I found online.
Upvotes: 0
Reputation: 133370
Use (fake) aggregation function
SELECT
T1."CardName"
,min( T0."Dscription")
, T0."DocEntry"
FROM INV1 T0
INNER JOIN OINV T1 ON T0."DocEntry" = T1."DocEntry"
INNER JOIN NNM1 T2 ON T1."Series" = T2."Series"
WHERE T1."DocTotal" > 1000
AND T0."DocDate" between [%1] and [%2]
GROUP BY T1."CardName", T0."DocEntry"
Upvotes: 2