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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with union

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2004-02-27 : 03:44:18

I havent had the need to use a union before, but I think in this case I do. I have 3 tables of email addresses that I must return as 1 column. I must add something that excludes all emails from tblUnsubscribe, I also must make sure that I dont bring back duplicate rows. How can I work a distinct across 2 unions?


Thanks alot for any tips / suggestions

mike123




CREATE PROCEDURE select_mailingList

AS SET NOCOUNT ON
select emailaddress from tblUserDetails where mailinglist ='1'
union
select email from tblEmailList
union
select emailaddress from tblUserDetails2 where mailinglist ='1'


GO

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-02-27 : 03:54:12
When you use UNION it brings back distinct rows automaticaly
when you use UNION ALL it does not.


Duane.
Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2004-02-27 : 03:55:46
awesome

any idea on how to add something that eliminates all rows that are selected from a "DoNotMail" table?


thanks alot
mike123


Go to Top of Page

rihardh
Constraint Violating Yak Guru

307 Posts

Posted - 2004-02-27 : 03:57:16
Duplicate rows should be excluded automatically unless you use UNION ALL.

To exclude records add "...AND ?email? NOT IN (SELECT ?email? from tblUnsubscribe)" to every where clause.
Go to Top of Page
   

- Advertisement -