Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Include dupes

Author  Topic 

ObiJuan
Starting Member

2 Posts

Posted - 2009-10-05 : 13:33:06

I’m using a query to join tables. However, if there is a duplicate, it only selects one record. I attached screenshots of the table and query. The first image is the table with the duplicate records highlighted, and the second is the query showing only 1 of the duplicates. SQL statement is below:

SELECT tblSnapfishReturns.[Transaction ID], tblSnapfishReturns.NegAmount AS Amount, tblSnapfishReturns.Date FROM tblSnapfishReturns
UNION SELECT tblCardSales.[PMT ID], tblCardSales.[total sale], tblCardSales.[shipping time]
FROM tblCardSales;


rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-10-05 : 13:36:08
use UNION ALL instead of UNION
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-05 : 13:37:06
Use UNION ALL instead of UNION.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-10-05 : 13:38:35
yes exactly :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-05 : 13:39:59
I'm a bit slow this morning. Left the topic open too long without posting the solution and you beat me to it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

ObiJuan
Starting Member

2 Posts

Posted - 2009-10-05 : 14:35:31
WOW - I just got back from lunch and saw it was already solved. Thanks for the lighting fast response.

UNION ALL worked like a charm. Thank you!!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-05 : 14:42:25
quote:
Originally posted by ObiJuan

WOW - I just got back from lunch and saw it was already solved. Thanks for the lighting fast response.

UNION ALL worked like a charm. Thank you!!



You're allowed to go to Lunch?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-05 : 14:48:51
These days, I'm barely even allowed to go home.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -