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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Simple Sql Join Help

Author  Topic 

ckuo@kahluadesigns.com
Yak Posting Veteran

58 Posts

Posted - 2002-08-13 : 17:45:24
I'm sure there is a simple answer to this but I just dont know. In my products table i have FirstOptionID and SecondOptionID, but joined to the ProductOptions table. How do I return the name for the FirstOptionName and the SecondOptionName? Thanks

SELECT
Products.ProductID,
??FirstOptionName??,
??SecondOptionName??,
Products.FinalPrice
FROM ProductOptions INNER JOIN
Products ON ProductOptions.OptionID = Products.FirstOptionID AND ProductOptions.OptionID = Products.SecondOptionID

r937
Posting Yak Master

112 Posts

Posted - 2002-08-13 : 18:21:59
you need to join to the options table twice

SELECT Products.ProductID, 
, o1.OptionName as FirstOptionName
, o2.OptionName as SecondOptionName
, Products.FinalPrice
FROM Products
INNER
JOIN ProductOptions o1
ON o1.OptionID = Products.FirstOptionID
INNER
JOIN ProductOptions o2
ON o2.OptionID = Products.SecondOptionID


rudy
Go to Top of Page
   

- Advertisement -