R
ryan.fitzpatrick3
I have this SQL code below. It takes 5 tables which for example are
1,2,3,4,5, 5 is subtable of 4, 4 of 3, 3 of 2, and 2 of 1. So when you
open table 1 up it can go to table 5. This code below takes those 5
tables and only finds the unique value in compared table. So lets say:
table 1
auto# Class
1 Ingredients
2 Packaging
Currently the subtable (table 2) has both ingredients and packaging
items together, it would look like this
autonum Category Class
1 Commodities Ingredients
2 Crops Ingredients
3 Dairy Ingredients
4 Label Packaging
5 Resin Packaging
6 Corrugated Packaging
....
17
table 3 or subsubtable would look like, this table has all category
items together, ultimately both ingredient and packaging.
GroupItems Category
1 Oil Commodities
2 Flour Commodities
3 Fruit Crops
4 Nuts Crops
5 Milk Dairy
6 Resin LDPE Resin
7 Promo Label
....
40
The code I should work like this. In table 3 it has Oil which is a
Commodity, so the code should eliminate Commodity out of the returned
query results, and so on for the rest of the items. Here is the code.
SELECT [tblclass].classNAME
FROM [tblClass]
WHERE ClassName NOT IN (SELECT DISTINCT categoryname FROM
tblCategories)
UNION
SELECT [tblCategories].categoryname
FROM [tblCategories]
WHERE categoryname NOT IN (SELECT DISTINCT groupName FROM tblgroup)
UNION
SELECT [tblgroup].groupNAME
FROM [tblgroup]
WHERE groupNAME NOT IN (SELECT DISTINCT ItemClassName FROM
tblItemClass)
UNION
SELECT [tblItemClass].itemclassname
FROM [tblItemClass]
WHERE ItemClassName NOT IN (SELECT DISTINCT ItemSubClassName FROM
tblItemSubClass)
UNION SELECT [tblItemsubClass].itemsubclassNAME
FROM [tblItemsubClass];
Basically it'll take the last most unique record in each table
providing that there is not a subtable that has information for that
one record. Any ideas. currently it just pulls everything all items
from table 1 to 5.
Ryan
1,2,3,4,5, 5 is subtable of 4, 4 of 3, 3 of 2, and 2 of 1. So when you
open table 1 up it can go to table 5. This code below takes those 5
tables and only finds the unique value in compared table. So lets say:
table 1
auto# Class
1 Ingredients
2 Packaging
Currently the subtable (table 2) has both ingredients and packaging
items together, it would look like this
autonum Category Class
1 Commodities Ingredients
2 Crops Ingredients
3 Dairy Ingredients
4 Label Packaging
5 Resin Packaging
6 Corrugated Packaging
....
17
table 3 or subsubtable would look like, this table has all category
items together, ultimately both ingredient and packaging.
GroupItems Category
1 Oil Commodities
2 Flour Commodities
3 Fruit Crops
4 Nuts Crops
5 Milk Dairy
6 Resin LDPE Resin
7 Promo Label
....
40
The code I should work like this. In table 3 it has Oil which is a
Commodity, so the code should eliminate Commodity out of the returned
query results, and so on for the rest of the items. Here is the code.
SELECT [tblclass].classNAME
FROM [tblClass]
WHERE ClassName NOT IN (SELECT DISTINCT categoryname FROM
tblCategories)
UNION
SELECT [tblCategories].categoryname
FROM [tblCategories]
WHERE categoryname NOT IN (SELECT DISTINCT groupName FROM tblgroup)
UNION
SELECT [tblgroup].groupNAME
FROM [tblgroup]
WHERE groupNAME NOT IN (SELECT DISTINCT ItemClassName FROM
tblItemClass)
UNION
SELECT [tblItemClass].itemclassname
FROM [tblItemClass]
WHERE ItemClassName NOT IN (SELECT DISTINCT ItemSubClassName FROM
tblItemSubClass)
UNION SELECT [tblItemsubClass].itemsubclassNAME
FROM [tblItemsubClass];
Basically it'll take the last most unique record in each table
providing that there is not a subtable that has information for that
one record. Any ideas. currently it just pulls everything all items
from table 1 to 5.
Ryan