Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have two tables, they have most fields in common however there are fields in table1 which are not in table2 and vice versa.Is there a query I can use to get all records from one table and all records from the other.I want the result set to contain all fields from both tables.What i'm looking for really is a UNION ALL type result but using tables with different fields.Thanks
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2007-07-24 : 08:01:15
If both table have matching records, meaning records in table1 exists in table2 and vice versa, you can just use INNER JOIN
The records in T1 dont relate in any way to T2, what I mean is there is no primary/foreign key relationship between them
Mondeo
Constraint Violating Yak Guru
287 Posts
Posted - 2007-07-24 : 09:45:59
ExampleTable1CDID Make Model Engine2087 Ford Mondeo 1.87765 Audi A4 2.07676 BMW 318i 1.9Table 2Make Model Derivative CustomerAudi A6 1.8 SE 5dr SMITHCit C5 2.0S JONESDesired ResultsCDID Make Model Engine Derivative Customer2087 Ford Mondeo 1.8 NULL NULL7765 Audi A4 2.0 NULL NULL7676 BMW 318i 1.9 NULL NULLNULL Audi A6 NULL 1.8 SE 5Dr SMITHNULL CIT C5 NULL 2.0S JONESThanks
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2007-07-24 : 09:47:16
you just want a result set that combines all records of both table ?