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
 Joining of two SQL columns

Author  Topic 

deanfp
Starting Member

26 Posts

Posted - 2012-03-26 : 11:28:26
Hi

I have a product table that lists all Product ID's from our database against a master Code. Some of these Product ID's are mapped to categories which is stored in another table. So what I have is

Table 1

ProductID (Full List)
SKU (Full List)

Table 2

ProductID (partial list of those products mapped to a category)

What SQL Script will be able to join these so that I can extract ProductID and SKU for only those ProdcutID mapped to a category?

It's basically mapping two columns from to tables.

deanfp
Starting Member

26 Posts

Posted - 2012-03-26 : 11:33:49
I was thinking something like SELECT ProductID,SKU FROM Product WHERE ProductID IS NOT NULL FROM ProductCategory
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-26 : 11:40:04
The INNER JOIN will return only rows which have a match in the second table:

select t1.ProductID, t1.SKU
from Table1 as t1
inner join Table2 as t2 on t2.ProductID = t1.ProductID


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

deanfp
Starting Member

26 Posts

Posted - 2012-03-26 : 11:52:58
Thanks! Worked great
Go to Top of Page
   

- Advertisement -