Re: Union query dropping "duplicate" rows
From: Ray Higdon (sqlhigdon_at_nospam.yahoo.com)
Date: 02/28/04
- Next message: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- Previous message: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- In reply to: Don Jellie: "Union query dropping "duplicate" rows"
- Next in thread: Don Jellie: "Re: Union query dropping "duplicate" rows"
- Reply: Don Jellie: "Re: Union query dropping "duplicate" rows"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 28 Feb 2004 13:36:53 -0500
Try UNION ALL, UNION ALL does not remove dupes
-- Ray Higdon MCSE, MCDBA, CCNA --- "Don Jellie" <anonymous@discussions.microsoft.com> wrote in message news:9A3F81D7-AAB4-4358-AF32-1C43DEEEF7A1@microsoft.com... > 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: Vishal Parkar: "Re: Union query dropping "duplicate" rows"
- In reply to: Don Jellie: "Union query dropping "duplicate" rows"
- Next in thread: Don Jellie: "Re: Union query dropping "duplicate" rows"
- Reply: Don Jellie: "Re: Union query dropping "duplicate" rows"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|