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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to join this

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2011-11-21 : 21:48:04
Hi there,

Scenario like this:
table1 has column of ProdCode with rows about 20
ABC
CVB
PLK
...

table2 has same column with qbout 30 rows as:
ABC
YPL
PLK
...

I tried to copy all the ProdCode from 2 tables, both same and not the same to a new tabel3 make it looks as: (dash line means white space)
ProdCode_1---------------ProdCode2
ABC----------------------ABC
CVB----------------------
PLK----------------------PLK
...
How can the code be? Thanks.


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-21 : 22:02:12
[code]
SELECT *
FROM table1 t1 LEFT JOIN table2 t2 ON t1.col = t2.col
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-11-22 : 03:08:04
Do left join so that you will get data as required

like
ProdCode_1--------------ProdCode2
ABC----------------------ABC
CVB----------------------

insert into tabel3(prodcode1,prodcode2)
SELECT t1.prodcode1,t2.prodcode2
FROM table1 t1 LEFT JOIN table2 t2 ON t1.col = t2.col
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-22 : 03:12:34
quote:
Originally posted by jassi.singh

Do left join so that you will get data as required

like
ProdCode_1--------------ProdCode2
ABC----------------------ABC
CVB----------------------

insert into tabel3(prodcode1,prodcode2)
SELECT t1.prodcode1,t2.prodcode2
FROM table1 t1 LEFT JOIN table2 t2 ON t1.col = t2.col


whats the use of copy pasting same suggestion like this?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -