SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 combine two tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

missMac
Posting Yak Master

124 Posts

Posted - 01/19/2009 :  13:38:34  Show Profile  Reply with Quote
how do I combine two tables?

ie i have a table that logs invalid phone numbers entered and another with unprocessed numbers and reason.

both have similar columns. ie

Table 1: failed
columns: ID, number, reason

Table 2: unprocessed numbers
columns: ID, numbers, reason

do i use union all ?

thanks


MM



revdnrdy
Posting Yak Master

USA
220 Posts

Posted - 01/19/2009 :  13:49:30  Show Profile  Reply with Quote
Hello;

UNION ALL will return duplicate rows. If you have a phone number characterized as unprocessed and invalid (for some reason) then the record will show up twice. Also the tables must be identical in structure (same columns & datatypes).

If thats ok then use something like this:

SELECT ID, number, reason FROM failed
UNION ALL
SELECT ID, number, reason FROM [unprocessed numbers]

r&r

Edited by - revdnrdy on 01/19/2009 13:50:09
Go to Top of Page

asgast
Posting Yak Master

149 Posts

Posted - 01/20/2009 :  03:40:45  Show Profile  Reply with Quote
if you don't want duplicate values just use union
Go to Top of Page

bjoerns
Posting Yak Master

Germany
154 Posts

Posted - 01/20/2009 :  04:26:36  Show Profile  Reply with Quote
No, asgast, as long as ID or reason is SELECTed, union will still give duplicate phone numbers.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 01/20/2009 :  08:53:40  Show Profile  Reply with Quote
quote:
Originally posted by bjoerns

No, asgast, as long as ID or reason is SELECTed, union will still give duplicate phone numbers.



yup thats true. It just looks for distinct combination of id,reason,number values rather than simply distinct of numbers alone
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000