Believe it or not this is something I have just never needed to do. A database was set up with two seperate tables relating on a Name field. How does one merge the two tables together without loss of data?
TAKE COPIES OF THE TABLES FIRST - voice of pain here!!
You need to open the one table (table one, for example) in design mode and add in the fields that you want from table 2. Next, create a select query over table 2. Drag all the fields into the query (NOT using the * button, but select the first and shift/click the last).
Change the query to an update query, and it will ask you for the table to update to, and (providing the field names are the same across the two tables) it will automatically input the name of the relevant field in table 1.
If I understand your post correctly, you have two tables with different data but a related column, Name? Is this correct? Do you want to create a new table that contains data from both existing tables? Or do you just want to select columns from matching rows both tables into one row?
How many columns do each of the tables have? Is there any duplication of columns in the two tables?
To Select all columns from both tables You'll want to JOIN the tables on the Name column. You should specifically list column names in the select list to avoid duplication of column names.
Select
a.name, a.col2, a.col3, ..., a.colN,
b.col2, b.col3, ..., b.colN
From Table1 As a
Inner Join Table2 As b
On a.name=b.name
You can convert the Seelct query to a make table query to create the new table with all of the cloumns.
Select
a.name, a.col2, a.col3, ..., a.colN,
b.col2, b.col3, ..., b.colN Into Table3
From Table1 As a
Inner Join Table2 As b
On a.name=b.name
Run the query to create the table and insert all of the data. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.