Union query dropping "duplicate" rows
From: Don Jellie (anonymous_at_discussions.microsoft.com)
Date: 02/28/04
- Next message: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- Previous message: Anith Sen: "Re: Arithmatic overflow with AVG?"
- Next in thread: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- Reply: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- Reply: Ray Higdon: "Re: Union query dropping "duplicate" rows"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 28 Feb 2004 07:11:34 -0800
Hi all,
I have 3 questions about the same issue. I a have union query across 2 almost identical inventory tables (1 current year & 1 historical) that is dropping rows it thinks are duplicates. They're not dups, though. They just look like it. The real thing is massive, but a simplified example follows.
SQL:
SELECT
CLASS, ITEM, SUM(COUNT)
FROM
CURRENT_TBL
GROUP BY
CLASS, ITEM
UNION
SELECT
CLASS, ITEM, SUM(COUNT)
FROM
HISTORY_TBL
GROUP BY
CLASS, ITEM
Orde by 1, 2
Data:
CLASS ITEM COUNT
Fruit Apples 7
Fruit Apples 100
Veggies Peas 50
Veggies Peas 50 (This row gets dropped!)
Questions:
1) Why is this happening and should I have expected it?
2) Is there syntax that will pull both the current and historical veggie rows even though they're identical?
3) I tried solving this by adding a unique column to each union (e.g. SELECT 'CUR' AS CUR, CLASS, ITEM, SUM(COUNT)) but I get an error on GROUP BY CUR, CLASS, ITEM. Can I not do that or is my syntax just bad?
Thanks a lot in advance,
DJ
- Next message: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- Previous message: Anith Sen: "Re: Arithmatic overflow with AVG?"
- Next in thread: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- Reply: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- Reply: Ray Higdon: "Re: Union query dropping "duplicate" rows"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|