?
Solved

T-SQL UNION - vanishing records

Posted on 2010-04-09
5
Medium Priority
?
289 Views
Last Modified: 2012-05-09
Hi,

I thought I've seen it all :)  Now I'm convinced there are gremlins running around in my trusted SQL.

I run two views without a UNIION clause and get 5 and 11 records respectively (total 16).  I run the UNION between the views and get 14 records.  I was missing 1 record from each view.

I'm scratching my head.

Thanks for any insight into this command.

Todd

UNION.jpg
No-UNION.jpg
0
Comment
Question by:Todd_Fields
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 30223765
Change UNION to UNION ALL

Raj
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 2000 total points
ID: 30223816
UNION ALL

UNION combines records.  UNION ALL will produce your duplicates.
0
 

Author Closing Comment

by:Todd_Fields
ID: 31712842
Bingo ...

I've never seen that case.  I'm wiser for your sharing this.

Regards.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 30223928
You're welcome.  Also check out the EXCEPT and INTERSECT TSQL operators...more fun stuff.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 30224100
:)

Raj
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question