Corticus
Well-known Member
- Joined
- Apr 30, 2002
- Messages
- 1,579
Hi all,
I've got a twisted question for you.
I made a query that does what I need, but its really slow, so there must be a better way.
I'm interested in 2 columns of data. One is a part number, and one is a component number. You might see data like this:
Part
10A
10A
10A
10B
10B
1034
1034
1000A01
Component
1034
1035
1036
A5454
A5454
1000A01
1000A02
L16545
I need a list of every part for a 10A, which would be:
Part
1034
1035
1036
1000A01
1000A02
L16545
As you can see, the trick is that a component can also be a part, which can have more components, and those components also can have components...
My nasty solution for the example would implement SQL as follows:
part I
QryParts
this makes a list of all the parts and relationships
first it gets filtered by a combo so it just shows one Part
SELECT
FROM ((TblItem LEFT JOIN TblItem AS TblItem_1 ON TblItem.Component = TblItem_1.Part) LEFT JOIN TblItem AS TblItem_2 ON TblItem_1.Component = TblItem_2.Part) LEFT JOIN TblItem AS TblItem_3 ON TblItem_2.Component = TblItem_3.Part;
Ugh...
part II
this gives the actual list of components for the part
SELECT DISTINCT QryParts.TblItem.Part
FROM QryParts
UNION SELECT DISTINCT QryParts.TblItem_1.Part
FROM QryParts;
UNION SELECT DISTINCT QryParts.TblItem_2.Part
FROM QryParts
UNION SELECT DISTINCT QryParts.TblItem_3.Component
FROM QryParts;
I just don't understand why its slow.....
Thanks for any help,
Corticus
I've got a twisted question for you.
I made a query that does what I need, but its really slow, so there must be a better way.
I'm interested in 2 columns of data. One is a part number, and one is a component number. You might see data like this:
Part
10A
10A
10A
10B
10B
1034
1034
1000A01
Component
1034
1035
1036
A5454
A5454
1000A01
1000A02
L16545
I need a list of every part for a 10A, which would be:
Part
1034
1035
1036
1000A01
1000A02
L16545
As you can see, the trick is that a component can also be a part, which can have more components, and those components also can have components...
My nasty solution for the example would implement SQL as follows:
part I
QryParts
this makes a list of all the parts and relationships
first it gets filtered by a combo so it just shows one Part
SELECT
FROM ((TblItem LEFT JOIN TblItem AS TblItem_1 ON TblItem.Component = TblItem_1.Part) LEFT JOIN TblItem AS TblItem_2 ON TblItem_1.Component = TblItem_2.Part) LEFT JOIN TblItem AS TblItem_3 ON TblItem_2.Component = TblItem_3.Part;
Ugh...
part II
this gives the actual list of components for the part
SELECT DISTINCT QryParts.TblItem.Part
FROM QryParts
UNION SELECT DISTINCT QryParts.TblItem_1.Part
FROM QryParts;
UNION SELECT DISTINCT QryParts.TblItem_2.Part
FROM QryParts
UNION SELECT DISTINCT QryParts.TblItem_3.Component
FROM QryParts;
I just don't understand why its slow.....
Thanks for any help,
Corticus