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

  • Home
  • SEARCH
  • 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 6227035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:08:33+00:00 2026-05-24T09:08:33+00:00

I have two tables: orders (id); order_items(id, order_id, item_id, quantity) Let’s say I have

  • 0

I have two tables:

  1. orders (id);
  2. order_items(id, order_id, item_id, quantity)

Let’s say I have already selected an order X with 3 different items (A – 1 unit, B – 2 units and C – 1 unit).

I need to get all the orders that have same items and exactly the same quantity of items (in this case: A – 1 unit, B – 2 units and C – 1 unit and no more or no less :)), excluding an order X.

i made a dump of test tables, so, I hope, for You would be easier to understand, what I’d like to get:) http://nopaste.info/44eb93ae3d.html

lets assume order X = 1, so desired output would be only the order 2, because order 3 has only one item and order 4 has same items as #1, but it has also one item extra, so it is not good 🙂

  • 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-05-24T09:08:33+00:00Added an answer on May 24, 2026 at 9:08 am

    Count the same occurence of each orders in the order_items table, and then compare to the number of item of the searched order:

    SELECT i2.order_id
    FROM order_items i1
        RIGHT OUTER JOIN order_items i2
            ON i2.item_id = i1.item_id 
            AND i2.quantity = i1.quantity
            AND i1.order_id = 1
    WHERE i2.order_id  != 1
    GROUP BY i2.order_id
    HAVING COUNT(i1.order_id) = COUNT(*)
       AND COUNT(i1.order_id) = (SELECT COUNT(*) FROM order_items WHERE order_id = 1)
    

    Note that this query assume that (order_id, item_id) is a Key of the order_items table.

    I have made a sample test here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two tables -- Products and Orders. For the sake of
Lets say I have data in two tables. In one I have Order ID
I have two tables: orders and orders_items. Both sharing the field orderID. I want
I have two Tables. Order - With Columns OrderID, OrderStatusID OrderStatus - With Columns
If I have two tables, Customers and Orders, and I want to look up
Using sqlite3, I have two tables: products, orders. I want to know how many
Suppose I have a dataset with those two immortal tables: Employee & Order Emp
I have the following two tables as a part of my order processing system:
I have two tables orders and orderdetails table orders (PK = id, UNIQUE index
I have two tables that are joined together. A has many B Normally you

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.