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.
For Question No. 1
As you can see below, the query is nested.
Subquery 2 gets all the orders_id which has
Wireless Mouseon it.Subquery 1 counts the number of records for each
Orders_IDin whichWireless Mouseis present.Main Query joins the subquery from
products_ordersandproductsMain Query -- Subquery 1 --- Subquery 2Query.
For Question No 2
From
Question No 1, you can just add addition condition on theWHEREclause to filter all records withoutWireless MouseQuery,
For Question No 3
just like question No 2, add extra condition
Query,