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 8761187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:13:40+00:00 2026-06-13T15:13:40+00:00

how can i extract specific bundle product orders from the following tables. for example,

  • 0

how can i extract specific bundle product orders from the following tables. for example, if i wanna extract all orders where product Wireless Mouse has been used as bundle products.

Expecting result 1:

    orders_id     product_name       qty    
       1000      Wireless Mouse      1
       1000      Laptop              1
       1001      Wireless Mouse      3
       1001      PC                  3
       1003      Wireless Mouse      4
       1003      IPAD                4

Second Question:

if i wanna extract only the products orders which are used with “Wireless Mouse” as bundle how can I do that?

Expecting result 2:

    orders_id     product_name       qty    
       1000      Laptop              1
       1001      PC                  3     
       1003      IPAD                4 

if possible please help me about the following:

if i wanna extract only the “Laptop” orders which are used with “Wireless Mouse” as bundle how can I do that?

Expecting result 3:

    orders_id     product_name       qty    
       1000      Laptop              1  

Example Data:

Table 1: orders

    id   customer_id      order_price  purchase_date
    1000   1                   203     12/6/2011
    1001   2                   304     12/6/2011
    1002   1                   1000    12/6/2011
    1003   1                   233     12/6/2011
    1004   1                   44      12/7/2011
    1005   3                   50      12/7/2011
    1006   4                   67      12/7/2011
    1007   5                   99      12/7/2011
    1008   6                   299     12/7/2011
    1009   7                   199     12/7/2011

Table 2 : customers


    id  email                          name
    1   aa@dealboard.com.au            james
    2   bb@dealboard.com.au            Ryan
    3   cc@live.com.au                 Sili
    4   dd@acgglobal.com               Mame
    5   ee.heinrich@det.nsw.edu.au     Kane
    6   ff@optusnet.com.au             Kratos
    7   ssy@hotmail.com                Kim

table 3: products


    id  name
    1   Laptop
    2   PC
    3   Wireless Mouse
    4   IPAD
    5   iphone
    6   Wireless Keyboard
    7   Printer
    8   Glaxy S3
    9   Scanner
    10  PS3

table 4: product_orders

    id     orders_id product_id qty
        1   1000      1         1
        2   1000      3         1
        3   1001      2         3
        4   1001      3         3
        5   1003      4         4
        6   1003      3         4
        7   1004      5         1
        8   1005      6         1
        9   1007      7         2
        10  1008      8         1

Sorry guys, i have asked too much today.

  • 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-13T15:13:41+00:00Added an answer on June 13, 2026 at 3:13 pm

    For Question No. 1

    As you can see below, the query is nested.

    Subquery 2 gets all the orders_id which has Wireless Mouse on it.
    Subquery 1 counts the number of records for each Orders_ID in which Wireless Mouse is present.
    Main Query joins the subquery from products_orders and products

    Main Query
      -- Subquery 1
         --- Subquery 2
    

    Query.

    SELECT   aaa.orders_id, bbb.name, aaa.qty
    FROM     products_orders aaa
             INNER JOIN products bbb
                 ON bbb.id = aaa.product_id
             INNER JOIN
              (
                SELECT  aa.ORDERS_ID
                FROM    products_orders aa
                        INNER JOIN
                        (
                          SELECT  orders_id
                          FROM    products_orders a
                                  INNER JOIN products b
                                    ON b.id = a.product_id
                          WHERE   name = 'Wireless Mouse'
                        ) bb ON aa.orders_id = bb.orders_id
                GROUP BY aa.ORDERS_ID
                HAVING COUNT(*) > 1
              ) ccc ON aaa.orders_id = ccc.orders_id
    ORDER BY aaa.orders_ID
    
    • SQLFiddle Demo

    For Question No 2

    From Question No 1, you can just add addition condition on the WHERE clause to filter all records without Wireless Mouse

    ...
    WHERE   bbb.name <> 'Wireless Mouse'
    

    Query,

    SELECT   aaa.orders_id, bbb.name, aaa.qty
    FROM     products_orders aaa
             INNER JOIN products bbb
                 ON bbb.id = aaa.product_id
             INNER JOIN
              (
                SELECT  aa.ORDERS_ID
                FROM    products_orders aa
                        INNER JOIN
                        (
                          SELECT  orders_id
                          FROM    products_orders a
                                  INNER JOIN products b
                                    ON b.id = a.product_id
                          WHERE   name = 'Wireless Mouse'
                        ) bb ON aa.orders_id = bb.orders_id
                GROUP BY aa.ORDERS_ID
                HAVING COUNT(*) > 1
              ) ccc ON aaa.orders_id = ccc.orders_id
    WHERE   bbb.name <> 'Wireless Mouse'
    
    • SQLFiddle Demo

    For Question No 3

    just like question No 2, add extra condition

    ...
    WHERE   bbb.name <> 'Wireless Mouse' AND
            bbb.name = 'Laptop'
    

    Query,

    SELECT   aaa.orders_id, bbb.name, aaa.qty
    FROM     products_orders aaa
             INNER JOIN products bbb
                 ON bbb.id = aaa.product_id
             INNER JOIN
              (
                SELECT  aa.ORDERS_ID
                FROM    products_orders aa
                        INNER JOIN
                        (
                          SELECT  orders_id
                          FROM    products_orders a
                                  INNER JOIN products b
                                    ON b.id = a.product_id
                          WHERE   name = 'Wireless Mouse'
                        ) bb ON aa.orders_id = bb.orders_id
                GROUP BY aa.ORDERS_ID
                HAVING COUNT(*) > 1
              ) ccc ON aaa.orders_id = ccc.orders_id
    WHERE   bbb.name <> 'Wireless Mouse' AND
            bbb.name = 'Laptop'
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out how to extract specific numbers with a specific match from
I want to create a java application that can extract specific sized icon from
How can I extract a specific field from each element of a Matlab struct
We can extract the mimetype from byte array, e.g., by using Apache Tika. Is
I'm looking for a parser that can extract methods from a java class (static
Is there any way by which i can extract a private key from a
I have some path c:\server\folderName1\another name\something\another folder\ . How i can extract from there
How can we extract a line from a multiLine EditText ? I tried this
How can I extract 456 from xxx_456 where xxx is of indefinite length?
i want to extract specific database tables & stored procedures into one master script.

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.