SQL Server - how to write query - Asked By srinu a on 08-Nov-12 10:12 PM

Hi friend i have small doubt in sql plz how to solve this one.

1)insert the data from one table to another table that time we write query like


select * into  (new table name) from  (existing table name)

like this way how to inssert multiple table data into one table .how we wirte query

acutal i have 2 table data like  1st table abc             id,name,sal andother table xyz    id,location
                                                                             1,add,100                                   1, hyd
                                                                              2,rav,2500                                   2,chen
                                                                               3,be,3600                                   7,pune
                                                                                                                               10,mumbai



i comine this table to write query    

 select  * from abc full join  xyz  on abc.id=xyz.id

this time all records retrive on both table.

this all data load  into another new table. how we write query plz tell me
new table create while we write one table data into aonther table like this way to write multiple table data into new table


plz tell how to wirte query
Robbe Morris replied to srinu a on 09-Nov-12 09:38 AM
insert into newTable(colA,colB,colC)
select a.Col1,a.Col2,b.col1 as col3
 from tableA a
 LEFT JOIN tableB b on a.primaryKeyColumn = b.foreignKeyColumn
WHERE some other stuff
srinu a replied to Robbe Morris on 19-Nov-12 03:29 AM
select * into xyy from(  select a.id1,a.name,a.deptno,b.dname from abc  a
full join  dept  b  on a  .deptno =b .deptno)a


select * from xyy 
we write like this way also