+ Reply to Thread
Results 1 to 3 of 3

Thread: mysql query issue

  1. #1

    mysql query issue

    I want to show uncategorized products in Magento , I have a product and category table , with a relation table called category_product. Every Product appears in two default categories (1 and 7). How would I construct a query that returns all Products who don't have any categories other than 2 and 5?
    Last edited by basemhosam; 01-10-2012 at 10:55 AM.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    30
    you can try the below code :
    Code:
    select p.product_id, p.name
    from category_product cp
    join product p on cp.product_id = p.product_id
    group by cp.product_id
    having sum(case when category_id in (1,7) then 0 else 1 end) = 0

  3. #3
    thank you , this is a good solution .

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts