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
 Other Forums
 MS Access
 Not sure how to JOIN another table?!

Author  Topic 

jarv
Posting Yak Master

131 Posts

Posted - 2009-12-22 : 10:55:25
Below is my SQL, Basically I have another table I need to join into the SQL The table name is: tblProductCategories
the columns are: ID, ProductID, CategoryID, ProductOrder
I know that its supposed to be something like:
INNER JOIN tblProductCategories ON tblProducts.ID=tblProductCategories.ProductID


rs.source = "SELECT tblProducts.RelatedProductID1, tblProducts.RelatedProductID2, tblProducts.RelatedProductID3, " &_
"tblProducts.Col_Manufact, tblProducts.Col_Brief, tblProducts.Image1, tblProducts.Image2, tblProducts.Image3, tblProducts.Image4, tblProducts.Image5, tblProducts.Thumb1, " &_
"tblProducts.Col_Model, tblProducts.Col_Desc, tblProducts.ProductID, tblProducts.ID, Col_ProdName, " &_
"tblProducts.Col_Price, tblCollections.CName " &_
"FROM tblCollections RIGHT JOIN tblProducts ON tblCollections.ID = tblProducts.Col_Manufact " &_
"WHERE tblProducts.ID=" & qsID & "AND (Season=" & intActiveSeason & " OR Season=4)"



this is what I have tried

rs.source = "SELECT tblProducts.RelatedProductID1, tblProducts.RelatedProductID2, tblProducts.RelatedProductID3, " &_
"tblProducts.Col_Manufact, tblProducts.Col_Brief, tblProducts.Image1, tblProducts.Image2, tblProducts.Image3, tblProducts.Image4, tblProducts.Image5, tblProducts.Thumb1, " &_
"tblProducts.Col_Model, tblProducts.Col_Desc, tblProducts.ProductID, tblProducts.ID, Col_ProdName, " &_
"tblProducts.Col_Price, tblCollections.CName, tblProductCategories.* " &_
"FROM tblCollections RIGHT JOIN tblProducts ON tblCollections.ID = tblProducts.Col_Manufact " &_
"INNER JOIN tblProductCategories ON tblProducts.ID=tblProductCategories.ProductID" & _
"WHERE tblProducts.ID=" & qsID & "AND (Season=" & intActiveSeason & " OR Season=4) ORDER BY tblProductCategories.ProductOrder Asc"

Ifor
Aged Yak Warrior

700 Posts

Posted - 2009-12-22 : 11:12:47
Try re-ordering the JOIN clause so the INNER JOIN comes first.

SELECT <whatever>
FROM tblProducts P
JOIN tblProductCategories PC
ON P.ID = PC.ProductID
LEFT JOIN tblCollections C
ON P.Col_Manufact = C.ID
WHERE <whatever>

Go to Top of Page

jarv
Posting Yak Master

131 Posts

Posted - 2009-12-22 : 11:32:16
no, I don't think it will be an INNER JOIN, why have you added PC and P.IP and C , C.ID??
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2009-12-31 : 05:27:45
quote:
Originally posted by jarv

no, I don't think it will be an INNER JOIN, why have you added PC and P.IP and C , C.ID??



Have you tried putting the INNER JOIN first?

PC, P etc are aliases.
Go to Top of Page
   

- Advertisement -