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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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 ?



Posting Yak Master

220 Posts

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

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
SELECT ID, number, reason FROM [unprocessed numbers]


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

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

Posting Yak Master

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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/20/2009 :  08:53:40  Show Profile  Reply with 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  
 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.02 seconds. Powered By: Snitz Forums 2000