So here is what I am trying to do. My boss wants to put all vehicles that we have on our homepage and randomly pull 8 of them at a time. The way our database schema is setup has the products, and categories in separate tables using a cross reference to locate the category the product falls under. The table with the categories has a parent that is a direct ID from another category. So here is the SQL that I came up with.
SELECT product.productID,
product.productSKU,
product.price,
product.name,
product.stateInd,
category.parentID,
category.categoryID,
prod_cat.productID FROM category
LEFT JOIN prod_cat
ON prod_cat.categoryID = category.categoryID
LEFT JOIN product
ON product.productID = prod_cat.productID
WHERE category.parentID = <cfqueryparam value="#catID#" cfsqltype="cf_sql_varchar" /> AND product.name <> "" AND RAND()
LIMIT 8
I hope that all makes sense. I am just having the hardest time not only pulling 8 products but also making sure those 8 products are unique. Oh and I did try putting DISTINCT after the select but the product was still selected twice.
Thanks!