Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outer Join syntax 1

Status
Not open for further replies.

Kingkumar

Programmer
Jan 21, 2003
167
US
Hi,
I am new to sql so not sure whether using outerjoin for the following scenario is a good idea or should use some other method.
I have two tables one has columns SSN, Lastname, firstname, sales and the second table has columns SSN,Lastname,Firstname , City.
Now i have data in tables THere are some ssn which are in first table and not in second table and vice versa but i need to have data for allthe SSN
how can i achieve that.
Thanks.

--King
 
Or do i need to use two queries to get all the data for both the tables ( i mean ssn for each table)
Thanks
--king
 
There is no need for two queries:
Code:
select 
isnull(A.SSN, B.SSN) as SSN,
isnull(A.LastName, B.LastName) as LastName,
isnull(A.FirstName, B.FirstName) as FirstName,
isnull(A.City, B.City) as City,
from table1 A
full outer join table2 B on A.SSN=B.SSN
-- order by ...



------
Math problems? Call 0800-[(10x)(13i)^2]-[sin(xy)/2.362x]
 
Code:
select * from table1 tb1
full outer join table2 tb2 on tb1.ssn = tb2.ssn



"I'm living so far beyond my income that we may almost be said to be living apart
 
Hey vongrunt thanks for the reply thats helpful but the problem i have is not all the columns are same one last column in both the tables is different one has sales and other city and i need both the columns in the final table
can you please help in that.

hey hmckillop thats not what i want i dont want repeated columns

Thanks guys for your help
--King
 
Simple: don't use ISNULL() for columns that exist only in one table.

------
Math problems? Call 0800-[(10x)(13i)^2]-[sin(xy)/2.362x]
 
Thats really dumb of me i think i am working too long so kinda brain dead :)
Thanks for your help you deserve a star :)
-King
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top