how to combine these queries into one using a join?
Hi there. I apologize but I'm a novice at sql...
I have to combine these two queries into one using a join:
SELECT categories.category_id, categories.title, categories.description,categories.parent_id,catego ries.display_weight,
categories.image_thumb, categories.deleted, categories.image_banner,
AND category_id <> 18
And here's the second one:
SELECT `product.product_id`, `product.name`, `product.image_thumb`, `product.deleted`
WHERE `product_id` IN (select product_id from product_category where category_id=18)
ORDER BY `display_weight` DESC
A few points:
It's possible to have a scenario where the first query will return 0 rows, but the second does contain records.
Also, you'll notice that the second query has a subquery baked in. The relationship between the product table and category table is defined in the product_category table.
The product table on its own doesn't know which categories the products belong to.