Hello, I'm trying to make a list of inventory to be counted, provided the item has had a sale in the last 2 months: I'm using Pervasive SQL and it's a BusinessVision table. This query works, but I don't know how to aggregate to have one item displayed:
SELECT "INVENTORY"."CODE", "INVENTORY"."INV_DESCRIPTION",
"INVENTORY"."BVSTKUOM", "INVENTORY"."INV_COMMITTED",
"INVENTORY"."ONHAND",
"SALES_HISTORY_HEADER"."IN_DATE"
FROM "INVENTORY" INNER JOIN "SALES_HISTORY_DETAIL" ON "SALES_HISTORY_DETAIL"."CODE" = "INVENTORY"."CODE" INNER JOIN "SALES_HISTORY_HEADER" ON "SALES_HISTORY_HEADER"."NUMBER" = "SALES_HISTORY_DETAIL"."NUMBER"
where "INVENTORY"."PROD" like 'A6O%' AND "SALES_HISTORY_HEADER"."IN_DATE" > '20090731'
Ok. This query would give me repeated results of a part number, with different dates. I just want to have one occurrence for each part number, provided it as sold in the last 2 months. For example:
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000 20090810
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000 20090811
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000 20090812
I would prefer simply have it like this:
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
and on the next row the next product. How can I do that?
EDITED PART AFTER SOME ANSWERS: Thanks for the suggestion about DISTINCT. I don't know why it repeats results yet. See (part of) the result of the query (not including "SALES_HISTORY_HEADER"."IN_DATE":
CODE INV_DESCRIPTION BVSTKUOM INV_COMMITTED ONHAND
--------------------------------------------------------- --------------- ----------
A6001-O15NP HP 700-101-O White 15" NP yds 0.00000 180.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
And when using the GROUP BY, or DISTINCT I get these results:
CODE INV_DESCRIPTION BVSTKUOM INV_COMMITTED ONHAND
--------------------------------------------------------- --------------- ----------
A6001-O15NP HP 700-101-O White 15" NP yds 0.00000 50.00000
A6001-O15NP HP 700-101-O White 15" NP yds 0.00000 180.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 0.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
I would expect just 2 rows, the ones with 180 and 915.