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 2008 Forums
 Transact-SQL (2008)
 Distinct result ?

Author  Topic 

Pete_N
Posting Yak Master

181 Posts

Posted - 2011-01-26 : 07:05:48
I have 2 tables containing client numbers, some of the client numbers appear in both tables. I for the life of me can not remmeber how to retun a query that gives me the client numbers from both tables. both ClientNumber fields are varchar fields
ie

Table 1
A100000
B100000
C100000

Table 2
B100000
B100001

Result
A100000
B100000
B100001
C100000

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-26 : 07:15:20
For example using 2 selects with UNION


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2011-01-27 : 21:24:36
select * from table1
intersect
select * from table2
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-28 : 01:47:38
quote:
Originally posted by namman

select * from table1
intersect
select * from table2


You need to use UNION

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -