Jump to content

Join Help


brianw

Recommended Posts

Hopefully some one can help point me in the right direction.  What I have is 2 tables, One for the SubCategories and one for the Products.  What I want to do is when someone clicks on the SubCategory page it pulls a random image from the Products table and lists it under the appropriate SubCategory.

 

I guess my question would be, how do I pull out the SubCategories, and have it select a random image out of the Products table and list it with the SubCategory?

 

This is what I have for the SQL, but what it does is returns records for ALL the products, when I just want to limit the return to 1 product image per subcategory.

 

SELECT *

FROM SubCategories RIGHT JOIN Products ON Products.ProductCategory = SubCategories.MainCategory

WHERE SubCategories.MainCategory = colname

ORDER BY SubCategories.`Order` ASC

 

Table Structures like like this:

 

SubCategories:

SubCategoryID

MainCategory

SubCategoryName

Order

 

Products:

ProductID

ProductCategory

ProductSubCategory

Manufacturer

ProductName

Model

ProductColor

ProductSize

ProductWeight

DiveDepth

Quantity

ProductDescription

ProductPrice

Retrieve

GearRatio

ItemsInStock

Recommendation1

Recommendation2

Recommendation3

Recommendation4

ProductImage

 

Link to comment
https://forums.phpfreaks.com/topic/125522-join-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.