I have a table with three category columns, a product may have one, two or three categories set.
My query is bring back a result for each so if for example
productid | productcategory | productcategory2 | roductcategory3 | otherstuff
1 | 5 | 3 | 6 |blah
this row will show up three times in my results as it is bringing it in for each category it finds. How do I distinct on union selects to make each one show up once only?
My query is bring back a result for each so if for example
productid | productcategory | productcategory2 | roductcategory3 | otherstuff
1 | 5 | 3 | 6 |blah
this row will show up three times in my results as it is bringing it in for each category it finds. How do I distinct on union selects to make each one show up once only?
Code:
SQL = "SELECT shop_products.productid, shop_products.shop_producers_id, shop_products.productcategory, shop_products.productcategory2, shop_products.productcategory3, shop_products.productname, shop_products.productlongdesc, shop_products.productprice, shop_products.productsaleprice, shop_productscategory.productcategoryname FROM shop_products INNER JOIN shop_productscategory ON shop_products.productcategory=shop_productscategory.id where shop_products.visible='1' AND shop_products.shop_producers_id = '"&Request.Cookies("AdminId")&"'"
SQL = SQL & " UNION SELECT shop_products.productid, shop_products.shop_producers_id, shop_products.productcategory, shop_products.productcategory2, shop_products.productcategory3, shop_products.productname, shop_products.productlongdesc, shop_products.productprice, shop_products.productsaleprice, shop_productscategory.productcategoryname FROM shop_products INNER JOIN shop_productscategory ON shop_products.productcategory2=shop_productscategory.id where shop_products.visible='1' AND shop_products.shop_producers_id = '"&Request.Cookies("AdminId")&"'"
SQL = SQL & " UNION SELECT shop_products.productid, shop_products.shop_producers_id, shop_products.productcategory, shop_products.productcategory2, shop_products.productcategory3, shop_products.productname, shop_products.productlongdesc, shop_products.productprice, shop_products.productsaleprice, shop_productscategory.productcategoryname FROM shop_products INNER JOIN shop_productscategory ON shop_products.productcategory3=shop_productscategory.id where shop_products.visible='1' AND shop_products.shop_producers_id = '"&Request.Cookies("AdminId")&"'"