brianw Posted September 23, 2008 Share Posted September 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/125522-join-help/ Share on other sites More sharing options...
fenway Posted September 29, 2008 Share Posted September 29, 2008 You're missing a limit clause. Quote Link to comment https://forums.phpfreaks.com/topic/125522-join-help/#findComment-653306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.