My query is not returning the expected amount of records
the first part returns 50.000 records
the second part (below the minus) returns 30.000
so as conclusion my minus should return 20.000 records.
only this is not happening more records are removed 21.000.
— edit —
the count returns more rows that expected, these returned records will in a later step be removed.
Anyone suggestions?
-- select count(*) from (
SELECT
loc.ITEM,
loc.loc
FROM ITEM_LOC loc
WHERE LOC NOT IN(101,104,107,115,116,117)
and loc.status = 'A'
and primary_supp in (select supplier from item_supplier where supp_discontinue_date >= sysdate)
-- );
minus
--; select count(*) from (
select distinct item, store from (
SELECT
siv.ITEM,
sto.store
FROM DC_CCN190_SID_VTB siv
JOIN DC_STORE_RANGING str ON siv.dpac = str.dpac
join store sto on sto.store_name_secondary = cast(str.loc as varchar2(150 byte))
where sto.store_close_date >= sysdate
union
SELECT
pim.ITEM,
sto.store
FROM dc_pim_export_vert PIM
JOIN DC_STORE_RANGING str ON PIM.dpac = str.dpac
join store sto on sto.store_name_secondary = cast(str.loc as varchar2(150 byte))
where PIM.artikel_type_lms = 'D1'
and sto.store_close_date >= sysdate
)
————————————————————————————-
count returns 50.000
select count(*) from (
SELECT
loc.ITEM,
loc.loc
FROM ITEM_LOC loc
WHERE LOC NOT IN(101,104,107,115,116,117)
and loc.status = 'A'
and primary_supp in (select supplier from item_supplier where supp_discontinue_date >= sysdate));
count returns 30.000
select count(*) from (
select distinct item, store from (
SELECT
siv.ITEM,
sto.store
FROM DC_CCN190_SID_VTB siv
JOIN DC_STORE_RANGING str ON siv.dpac = str.dpac
join store sto on sto.store_name_secondary = cast(str.loc as varchar2(150 byte))
where sto.store_close_date >= sysdate
union
SELECT
pim.ITEM,
sto.store
FROM dc_pim_export_vert PIM
JOIN DC_STORE_RANGING str ON PIM.dpac = str.dpac
join store sto on sto.store_name_secondary = cast(str.loc as varchar2(150 byte))
where PIM.artikel_type_lms = 'D1'
and sto.store_close_date >= sysdate
);
So the minus should return 20.000 right?
A = 50000. B = 30000. A – B = 21000. What is B – A? I’m expecting 1000. That is, there are 1000 records in B that are not included in A. In a simple case,
A returns 4 records
Jim
Bob
Mary
Samantha
B returns 3 records
Bob
Mary
Josephine
A – B returns 2 records:
Jim
Samantha
B – A returns 1 record:
Josephine