Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:22:42+00:00 2026-06-05T16:22:42+00:00

MYSQL I want to filter "orders" according to their items within a form’s checkboxes.

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:22:44+00:00Added an answer on June 5, 2026 at 4:22 pm

    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.

    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 -- start with orders
    
    -- add in the items, but use INNER to avoid orders that do not have
    -- at least one order_item whose id was checked
    INNER JOIN tbl_order_items I on I.order_id = O.id
               AND I.product_id in (1044,1129,20976,16775)
    -- left join in the items which were NOT checked.  If there are any, the
    -- rows will have bad product ids in them.
    -- But if there ARE NOT any bad items in the order, 
    -- then there will only be one row with NULL for BADITEMS.product_id
    LEFT JOIN tbl_order_items BADITEMS on BADITEMS.order_id = O.id
               AND BADITEMS.product_id NOT in (1044,1129,20976,16775)
    -- Pull in the product information
    INNER JOIN tbl_products P on P.id = I.product_id
    -- Pull in member information
    LEFT JOIN tbl_members M on M.id = O.member_id
    WHERE
         -- the inner join has already insured that we only get orders
         -- that have checked items.
         -- To remove the orders that ALSO had unchecked items,
         -- We take only rows where the BADITEMS join failed.
         BADITEMS.product_id IS NULL
    AND
         O.status_id = 311 and O.payment_status_id = 349
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just want to know how I can filter out a result using mysql if
I am trying to do a little spam filter with mysql. I want to
I am using Windows Form and MySQL for my project. In that i want
I store some data in MySQL and want to filter out rows that match
I want to filter my search results based on some parameters using checkboxes .I
I want to filter the data in my SQL so that I only have
I am in a learning way of mysql and want help to know where
I'm creating a Web interface for a table in Mysql and want to use
I have this mysql tables I want to display with jqgrid. The problem appears
I want to develop mysql database application using dbexpress to develop from scratch or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.