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
 Vlookup and Sum

Author  Topic 

jfm
Posting Yak Master

145 Posts

Posted - 2012-07-17 : 06:20:28
Hi there,

I have Table_1 and Table_2.

Table_1 has just Column_A, Table_2 has Column_A and many other columns.

I need to take the info from Table_1.Column_A and match with the same values of Table_2.ColumnA

Creating a New_Table using Table_2.Column_A (matched with Table_1.ColumnA values) and Column_P.

New Table= ColumnA, Column P

I'm trying yo use OUTER JOIN but is not working...

Any ideas? Thanks!

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2012-07-17 : 06:33:31
unable to understand

Creating a New_Table using Table_2.Column_A (matched with Table_1.ColumnA values) and Column_P.

New Table= ColumnA, Column P


--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 2012-07-17 : 06:50:46
Sorry for my explanation.

In Table_2, I have ID_Column and Postcode_Column.

In table_1, I only have ID_Column .

I need to match, the ID's that I have equal in both Tables, and create a New_Table that contains ID_Column and Postcode_Column (only the ones that matches with the ID_Column)

Thanks a lot


Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-17 : 06:53:04
use inner join


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 2012-07-17 : 07:53:55
I have a problem using INNER JOIN. Is working, but I can create the table.

Using:

Select * from Table_1
INNER JOIN Table_2
ON Table_1.ID = Table_2.ID

Its correct, but I don't have my table, in order to work with the data


So using:

Select Table_1.*
INTO Table_3
From Table_1
INNER JOIN Table_2
ON Table_1.Id = Table_2.ID

Table_3 just has the ID column, instead of having all the columns. And I need the data that I have using the first query.

Im sure im missing something in the process, but I don't know what.

Any idea?

Many thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-17 : 08:21:08
select
t1.Id,
t2.Column_P
into Table_3
from Table_1 as t1
inner join Table_2 as t2 on t1.Id = t2.Id



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 2012-07-17 : 09:38:32
Thanks for your reply,

I can use the query is working, this way:

select
t1.Id, t2.Column_P
into Table_3
from Table_1
inner join Table_2
on t1.Id = t2.Id

Many thanks



Go to Top of Page
   

- Advertisement -