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.
| 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 / suggestionsmike123CREATE PROCEDURE select_mailingList AS SET NOCOUNT ONselect emailaddress from tblUserDetails where mailinglist ='1'union select email from tblEmailListunion 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 automaticalywhen you use UNION ALL it does not.Duane. |
 |
|
|
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 alotmike123 |
 |
|
|
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. |
 |
|
|
|
|
|