mysql - A relational query, not sure how to build it with EXISTS -
carts id user_id cart_proucts id cart_id product_id price products details product...
so easier form of table structure currently. have list of product id, need check against user if has them or not, know looking @ cart_products cart belongs user, relationship described above. if has should retrieve "user" , information contains. need check if price range of product, i.e. product must not lower 500 i.e. price column in cart_products...
how can easiest build sql? thinking of joins , use of exists or in perhaps?
select * `users` `u` join `carts` `c` on (`u`.`id` = `c`.`user_id`) join `cart_products` `cp` on (`cp`.`cart_id` = `c`.`id`) join `products` `p` on (`p`.`id` = `cp`.`product_id` , `p`.`price` > `cp`.`price`) `p`.`id` in (...);
Comments
Post a Comment