hi all,

I am new to mssql but C# programmer, can anyone help me on how to merge columns from different tables to a single table in sql
for example
i've 4 tables and
the first table has a,b,c,d columns
second table has e,f,g,h
thrid table has i, j, k, l,m
fourth table has n,o,p columns

so now i want to retrieve a table so that the table should have
a,b,g,j,k,n,p columns

can anyone help me

Hi

Are the four tables related in any way? Is there a primary key / foreign key relationship between the tables...

If not you could try the following:

SELECT 
INTO New_Table
table1.a, table1.b, table2.g, table3.j, table3.k, table4.n, table4.p
FROM
table1, table2, table3, table4

If the tables are related through primary keys foreign keys you will have to join the tables

SELECT 
INTO New_Table
table1.a, table1.b, table2.g, table3.j, table3.k, table4.n, table4.p
FROM
table1 inner join table2 on table1.a = table2.e inner join table3 on table2.f = table3.i inner join table4 on table3 on table3.l = table4.o

Or however the relationships between the tables are defined in the database

thanks bruceoz, the tables are not related at all, i will try the first suggestion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.