DaveButler
IS-IT--Management
Are you a competent SQL developer? If so, please help me compose this seemingly simple, yet tricky, query.
Assume the data structure in question is the typical Order and LineItem. For each Order row, there are many LineItems associated with it. I need for the query to return *all* LineItem rows for each order that contain a purchase of product "X".
Assume the following data structures.
Table: Order
Column: OrderNum (PK)
Table: LineItem
Column: OrderNum (PK, FK)
Column: ProductID (PK)
So, let's assume that the database contains 3 orders.
Order 1 is for products A, B, and X (1 Order, 3 LineItems).
Order 2 is for products C, D, and E (ditto).
Order 3 is for products X, Y, and Z (ditto).
The data in LineItem looks like this.
1,A
1,B
1,X
2,C
2,D
2,E
3,X
3,Y
3,Z
The query needs to return the following rows of LineItem.
1,A
1,B
1,X
3,X
3,Y
3,Z
What does the query look like? I'm at a loss about how to get started.
Thanks for your help !!!
Regards,
Kim
Assume the data structure in question is the typical Order and LineItem. For each Order row, there are many LineItems associated with it. I need for the query to return *all* LineItem rows for each order that contain a purchase of product "X".
Assume the following data structures.
Table: Order
Column: OrderNum (PK)
Table: LineItem
Column: OrderNum (PK, FK)
Column: ProductID (PK)
So, let's assume that the database contains 3 orders.
Order 1 is for products A, B, and X (1 Order, 3 LineItems).
Order 2 is for products C, D, and E (ditto).
Order 3 is for products X, Y, and Z (ditto).
The data in LineItem looks like this.
1,A
1,B
1,X
2,C
2,D
2,E
3,X
3,Y
3,Z
The query needs to return the following rows of LineItem.
1,A
1,B
1,X
3,X
3,Y
3,Z
What does the query look like? I'm at a loss about how to get started.
Thanks for your help !!!
Regards,
Kim