mysql - SQL: Get all rows with value n associated with id -


lets have following tables cart, cart_data , product:

cart

cart_id total_cost

cart_data

cart_data_id cart_id product_id

product

product_id product_name

i'm trying select carts each product_id in cart_data must = 2 , return cart_id product_ids = 2

for example: if cart has 5 products have id = 2 cart_id should show.

however, if cart has 5 products has 4 products = 2 , 1 product = 4 shouldn't show up.

haven't tested should work:

select     cart_data.cart_id       cart_data      cart_data.cart_id in            ( select cart_data.cart_id                cart_data              group cart_data.cart_id              having min( cart_data.product_id ) = 2              ,    max( cart_data.product_id ) = 2            ) 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -