Before I go into it, let me state that I've received terrific assistance from this site before.. and it's now the first place I come to when researching query issues!
I'm working on a query that pulls from an OSCommerce database for products. Specifically, there are 4 tables I'm working with here..
products
products_to_categories
categories
categories_description
products_description
Ok, make that FIVE tables. lol
Let me start by pasting my current query:
Basically what I need to be able to do is add another column called "categories" that has the categories of the product concatenated together, separated by a comma.
The problem is, those category descriptions are in, well, categories_description.. which as of yet is not part of the query.
The table products_to_categories basically just consists of a couple fields. One with the product id, and one with the category id. So let's say product id #1 is in 5 categories. That product would be listed in products_to_categories 5 times. one for each category. What I want to do is take that list, look up the descriptions using the category id's supplied, and concat them into a field in the query. It hurts my brain to even think of how to do this, nevermind doing it in an efficient manner.
any help is appreciated!
thanks,
-s
I'm working on a query that pulls from an OSCommerce database for products. Specifically, there are 4 tables I'm working with here..
products
products_to_categories
categories
categories_description
products_description
Ok, make that FIVE tables. lol
Let me start by pasting my current query:
Code:
SELECT
manufacturers.manufacturers_name AS manufacturer,
products.products_id AS id,
products_description.products_name AS title,
CONCAT('store/product_info.php?product_id=', products.products_id) as link,
products.products_upc AS upc,
products.products_id AS mpc,
products.products_model AS mpn,
products.products_quantity AS quantity,
products_description.products_description AS description,
products.products_price AS price,
products.products_tax_class_id,
CONCAT('store/images/', products.products_image) as products_image,
products_to_categories.categories_id
FROM (products,
products_description,
products_to_categories)
LEFT JOIN manufacturers ON ( manufacturers.manufacturers_id = products.manufacturers_id )
WHERE
( products.products_id = products_description.products_id )
AND products.products_id = products_to_categories.products_id
AND products.products_status = 1
AND products.products_quantity > 0
ORDER BY products_to_categories.categories_id DESC
Basically what I need to be able to do is add another column called "categories" that has the categories of the product concatenated together, separated by a comma.
The problem is, those category descriptions are in, well, categories_description.. which as of yet is not part of the query.
The table products_to_categories basically just consists of a couple fields. One with the product id, and one with the category id. So let's say product id #1 is in 5 categories. That product would be listed in products_to_categories 5 times. one for each category. What I want to do is take that list, look up the descriptions using the category id's supplied, and concat them into a field in the query. It hurts my brain to even think of how to do this, nevermind doing it in an efficient manner.
any help is appreciated!
thanks,
-s