ventesites Posted September 24, 2016 Share Posted September 24, 2016 (edited) Hello I am trying to get the list of customers who bought specific products no longer available I got this request from the forum SELECT C.email FROM ps_customer CINNER JOIN ps_orders O on C.id_customer = O.id_customerINNER JOIN ps_order_detail OD on O.id_order = OD.id_orderWHERE OD.product_id IN (3,45,47,94,102) but it works only for available product ...(available_for_order=1) How can i modify the request to get the result for products no longer available, sold out? (available_for_order=0) Thanks Pat Edited September 24, 2016 by ventesites (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted September 25, 2016 Share Posted September 25, 2016 you can try this one SELECT C.email FROM ps_customer CINNER JOIN ps_orders O on C.id_customer = O.id_customerINNER JOIN ps_order_detail OD on O.id_order = OD.id_orderINNER JOIN ps_product p on od.Product_ID = p.id_product WHERE p.available_for_order = 0 1 Link to comment Share on other sites More sharing options...
ventesites Posted September 25, 2016 Author Share Posted September 25, 2016 I can't get the above requests to work so i tried using category SELECT C.email, C.lastname, C.firstname, P.id_product, PL.nameFROM ps_customer C, ps_product_lang PLINNER JOIN ps_orders O on C.id_customer = O.id_customerINNER JOIN ps_order_detail OD on O.id_order = OD.id_orderINNER JOIN ps_product P on OD.product_id = P.id_productWHERE P.available_for_order = 0AND P.id_category_default = 2246 It gave me "#1054 - Unknown column 'C.id_customer' in 'on clause'... what am i doing wrong? Link to comment Share on other sites More sharing options...
shokinro Posted September 25, 2016 Share Posted September 25, 2016 Your statement are using different table join. Please try this SELECT C.email, C.lastname, C.firstname, P.id_product, PL.name FROM ps_customer C INNER JOIN ps_orders O on C.id_customer = O.id_customer INNER JOIN ps_order_detail OD on O.id_order = OD.id_order INNER JOIN ps_product P on OD.product_id = P.id_product INNER JOIN ps_product_lang PL ON PL.id_product = P.id_product WHERE P.available_for_order = 0 AND P.id_category_default = 2246 1 Link to comment Share on other sites More sharing options...
ventesites Posted September 25, 2016 Author Share Posted September 25, 2016 now it's working with your help, thanks so much to every one for your input Link to comment Share on other sites More sharing options...
shokinro Posted September 25, 2016 Share Posted September 25, 2016 glad it worked and helped, and thanks for feedback. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now