I have this MySql query working partially:
SELECT p.product_id, p.product_name, p.sales,
p.length, p.hits, COUNT(w.product_id) AS favorites
FROM `products` AS p, `products_mf_xref` AS m,
`wishlist_items` AS w
WHERE m.manufacturer_id = '1'
AND p.product_id = m.product_id
AND m.product_id = w.product_id
GROUP BY m.product_id ORDER BY p.product_id ASC
I'm recovering some fields from a table and trying to get the number of times these products are referenced in another table (this last table was called "whishlist"). The query is working OK, but I only get the products that are at least one time referenced in the wish list table.
I read that count(*) does not get NULL values what make sense, but I need also the products that are not referenced in the wish list table, I mean, products where COUNT(w.product_id) are equal to "0".
Any idea to recover all the products, including the null values? Any idea to change my query? It's going to make me mad!!
Thanks in advance!