MYSQL
I want to filter "orders" according to their items within a form’s checkboxes.
For example,
I checked
ITEM A + ITEM B , but not ITEM C
ORDER 1
ITEM A
ORDER 2
ITEM B
ORDER 3
ITEM A
ITEM B
ITEM C
ORDER 4
ITEM A
ITEM B
What i want to have is:
ORDER 1 & ORDER 2 & ORDER 4 ,but not ORDER 3 because this has also ITEM C
MY QUERY LIKE THIS
SELECT
P.id as product_id,P.name as product_name,
O.id as order_id,O.group_id,O.payment_date,O.payment_type_id,I.quantity,
M.name,M.surname,M.email
FROM tbl_orders O
LEFT JOIN tbl_order_items I on I.order_id = O.id
LEFT JOIN tbl_products P on P.id = I.product_id
LEFT JOIN tbl_members M on M.id = O.member_id
WHERE
I.product_id in (1044,1129,20976,16775)
AND
O.status_id = 311 and O.payment_status_id = 349
Thank you
I’m guessing that the core problem is that you want to EXCLUDE orders which have any of the unchecked values, and INCLUDE orders which have at least one of the checked values.