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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.