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 2005 Forums
 Transact-SQL (2005)
 combine two tables

Author  Topic 

missMac
Posting Yak Master

124 Posts

Posted - 2009-01-19 : 13:38:34
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

220 Posts

Posted - 2009-01-19 : 13:49:30
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
Go to Top of Page

asgast
Posting Yak Master

149 Posts

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

bjoerns
Posting Yak Master

154 Posts

Posted - 2009-01-20 : 04:26:36
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

52326 Posts

Posted - 2009-01-20 : 08:53:40
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
   

- Advertisement -