self Join [Help Required]

  • Is it that you want the books that have the same price and sold by ALL the resellerIds you have in the table ? This is one way to accomplish that, try this one and let me know.

    [Code]

    SELECT *

    FROM mySampleData T1

    INNER JOIN (SELECT price, book_code

    FROM (SELECT price, book_code, resellerid

    FROM mySampleData

    GROUP BY price, book_code, resellerid

    ) BP

    GROUP BY price, book_code

    HAVING count(*) = (SELECT count(distinct resellerId) from mySampleData)

    ) T2 on T1.book_code = T2.book_code AND T1.price = T2.price

    ORDER BY T1.book_code

    ,T1.resellerid

    [/Code]

Viewing post 16 (of 15 total)

You must be logged in to reply to this topic. Login to reply