Hi everyone
Have a problem I would areally appreciate help with.
I have 3 tables in a standard format for a Bookshop, eg
Products
Categories
Categories_Prod ucts
the latter allowing me to have products in multiple categories.
Everthing works well except for one annoying little thing.
When an individual product (which is in more than one topcategory) is added
to the Shopping Cart it displays twice, because in my select statement I
have the Category listed. I realise I could remove the TopCategory from the
statement and that makes my DISTINCT work as I wanted, but Id prefer to have
the TopCategory as it saves me later having to another SQL query (Im already
doing one to allow me not to list category in the Statement .... but If I
can overcome this one ... then I can remove this as well).
Here is my table structure (the necessary bits)
products
idProduct int
....
categories
idcategory int
idParentCategor y int
topcategory int
...
categories_prod ucts
idCatProd int
idProduct int
idCategory
When I run a query such as
SELECT DISTINCT a.idProduct, a.description,a .descriptionLon g,
a.listPrice,a.p rice,a.smallIma geUrl,a.stock, a.fileName,a.no ShipCharge,
c.topcategory
FROM products a, categories_prod ucts b, categories c
WHERE active = -1 AND homePage = -1
AND a.idProduct = b.idProduct
AND c.idcategory=b. idcategory
AND prodType = 1 ORDER BY a.idProduct DESC
This will return all products as expected, as well as any products which are
in more than one TopCategory.
Any ideas how to overcome this would be greatly appreciated.
Cheers
Craig
Have a problem I would areally appreciate help with.
I have 3 tables in a standard format for a Bookshop, eg
Products
Categories
Categories_Prod ucts
the latter allowing me to have products in multiple categories.
Everthing works well except for one annoying little thing.
When an individual product (which is in more than one topcategory) is added
to the Shopping Cart it displays twice, because in my select statement I
have the Category listed. I realise I could remove the TopCategory from the
statement and that makes my DISTINCT work as I wanted, but Id prefer to have
the TopCategory as it saves me later having to another SQL query (Im already
doing one to allow me not to list category in the Statement .... but If I
can overcome this one ... then I can remove this as well).
Here is my table structure (the necessary bits)
products
idProduct int
....
categories
idcategory int
idParentCategor y int
topcategory int
...
categories_prod ucts
idCatProd int
idProduct int
idCategory
When I run a query such as
SELECT DISTINCT a.idProduct, a.description,a .descriptionLon g,
a.listPrice,a.p rice,a.smallIma geUrl,a.stock, a.fileName,a.no ShipCharge,
c.topcategory
FROM products a, categories_prod ucts b, categories c
WHERE active = -1 AND homePage = -1
AND a.idProduct = b.idProduct
AND c.idcategory=b. idcategory
AND prodType = 1 ORDER BY a.idProduct DESC
This will return all products as expected, as well as any products which are
in more than one TopCategory.
Any ideas how to overcome this would be greatly appreciated.
Cheers
Craig
Comment