| Author |
Topic  |
|
|
jfm
Posting Yak Master
134 Posts |
Posted - 05/18/2012 : 08:27:51
|
Hi there,
I need to merge, 3 tables.
I have 3 tables in the same database, but in order to work with my data (as given in my 3 tables) I need to join the 3 tables in a only new one.
Take table A, B,C and merge all them creating table D. The number of columns of each table is the same, and also the values
Any idea?
Thanks |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 05/18/2012 : 08:35:06
|
quote: The number of columns of each table is the same, and also the values
you mean the 3 tables are identical ?
How do you want to merge these 3 tables ?
KH Time is always against us
|
 |
|
|
jfm
Posting Yak Master
134 Posts |
Posted - 05/18/2012 : 08:44:58
|
The tree tables, have identical column names. The info inside each cell is different (they are numbers), but the data style is the same for each same column in each table.
Is the same as if you have all your info in tree sheets and you want to put the info in only one sheet.
quote: Originally posted by khtan
quote: The number of columns of each table is the same, and also the values
you mean the 3 tables are identical ?
How do you want to merge these 3 tables ?
KH Time is always against us
|
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 05/18/2012 : 08:45:49
|
select <column list> from table1 union all
select <column list> from table2 union all
select <column list> from table3
KH Time is always against us
|
 |
|
|
jfm
Posting Yak Master
134 Posts |
Posted - 05/18/2012 : 08:54:16
|
Perfect,
But i want also to put the tree tables into a new_table
I have tried:
select <column list> from table1 union all select <column list> from table2 union all select <column list> from table3 union all into Total_File
msg 156, level 15, state 1, line 4
quote: Originally posted by khtan
select <column list> from table1 union all
select <column list> from table2 union all
select <column list> from table3
KH Time is always against us
|
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 05/18/2012 : 08:56:07
|
SELECT <column list>
INTO NEW_TABLE
FROM
(
select <column list> from table1 union all
select <column list> from table2 union all
select <column list> from table3
) O
KH Time is always against us
|
 |
|
|
jfm
Posting Yak Master
134 Posts |
Posted - 05/18/2012 : 09:10:58
|
SELECT * INTO NEW_TABLE FROM
(SELECT * FROM TABLE_A UNION ALL SELECT * FROM TABLE_B UNION ALL SELECT * FROM TABLE_C )
Msg 102, level 15, state 1, line 5 incorrect syntax near ')'
I did the query using all the columns name, and I have the same msg..
Any idea?
Thanks a lot
quote: Originally posted by khtan
SELECT <column list>
INTO NEW_TABLE
FROM
(
select <column list> from table1 union all
select <column list> from table2 union all
select <column list> from table3
) O
KH Time is always against us
|
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 05/18/2012 : 09:13:37
|
you missed out the table alias O at the end
KH Time is always against us
|
 |
|
|
jfm
Posting Yak Master
134 Posts |
Posted - 05/18/2012 : 09:16:14
|
Its perfect!
Thank you very much. |
 |
|
| |
Topic  |
|