Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complex Query Question with Joins

Status
Not open for further replies.

amacfarl

Programmer
Jun 23, 2003
8
DE
Folks,

Have two tables:

TblHier Hierarchy Table
Fields Level0, Level1, Level2, Level3, Level4 (all int)

TblProduct Product Listings
Fields ProductNumber, Level0, Level1, Level2, Level3, Level4 (all int)

I am using the following query to count how many products have the correct hierarchy as detailed in the Hierarchy Table.

SELECT
Count(*)
FROM
TblProduct, TblHier
WHERE
TblProduct.Level0 = TblHier .Level0 AND
TblProduct.Level1 = TblHier .Level1 AND
TblProduct.Level2 = TblHier .Level2 AND
TblProduct.Level3 = TblHier .Level3 AND
TblProduct.Level4 = TblHier .Level4

My question is how to count and list the products that do not following the correct hierarchy... obviously this query does not work...

SELECT
Count(*)
FROM
TblProduct, TblHier
WHERE
TblProduct.Level0 <> TblHier .Level0 AND
TblProduct.Level1 <> TblHier .Level1 AND
TblProduct.Level2 <> TblHier .Level2 AND
TblProduct.Level3 <> TblHier .Level3 AND
TblProduct.Level4 <> TblHier .Level4


THANKS IN ADVANCE FOR YOUR HELP
 
Since &quot;Bad&quot; is the converse of &quot;Good&quot; ...

SELECT
Count(*)
FROM
TblProduct, TblHier
WHERE NOT (
TblProduct.Level0 = TblHier .Level0 AND
TblProduct.Level1 = TblHier .Level1 AND
TblProduct.Level2 = TblHier .Level2 AND
TblProduct.Level3 = TblHier .Level3 AND
TblProduct.Level4 = TblHier .Level4 )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top