Find pattern of data from three tables

  • Hey everyone

  • It seems a home work question :

    However solution is:-

    select pr.prodduct_id,pr.product_name from Product pr join

    ( select producti_id,(select count(1) as [States Count] from Restriction where product_id=p.Product_id group by state_id ) from Product P ) as Pro

    on pro.product_id=pr.product_id

    where

    pro.[States Count] = ( select count(distinct state_id) from State)

    Regards

    Ashok

  • ashok.faridabad1984 (8/18/2011)


    It seems a home work question :

    However solution is:-

    select pr.prodduct_id,pr.product_name from Product pr join

    ( select producti_id,(select count(1) as [States Count] from Restriction where product_id=p.Product_id group by state_id ) from Product P ) as Pro

    on pro.product_id=pr.product_id

    where

    pro.[States Count] = ( select count(distinct state_id) from State)

    Regards

    Ashok

  • There is small chnage in the script :hehe:

    select pr.prodduct_id,pr.product_name from Product pr join

    ( select producti_id,(select count(1) as [States Count] from Restriction where product_id=p.Product_id group by product_id ) from Product P ) as Pro

    on pro.product_id=pr.product_id

    where

    pro.[States Count] = ( select count(distinct state_id) from State)

    Regards

    Ashok

  • Thanks Ashok!:-) Appreciated.Ater thinking a little bit, I came up with this updated query:

    select pr.prodduct_id,pr.product_name from Product pr join

    ( select product_id,count(state_id) as [States Count] from Restriction group by product_id) as Pro

    on pro.product_id=pr.product_id

    where

    pro.[States Count] = ( select count(distinct state_id) from State)

    Thanks again!

Viewing 5 posts - 1 through 4 (of 4 total)

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