Very advanced query, checking for existing combinations...

I am trying to write a procedure which returns a simple boolean, 1 if an item exists in our database with the same combination of values as what the user defines from the UI.

The tables are structured such as:
itemNo, Property, Value

So you can have a table that looks like this:

001, a, 1
001, b, 2
001, c, 3
001, d, 0
002, a, 1
002, b, 2
002, c, 3
002, d, 4

Notice that the value of the D Property for itemNo 001 is 0, compared to 4 on itemNo 004. If a user is configuring up itemNo 003, like this...

003, a, 1
003, b, 2
003, c, 3
003, d, 0

... a message should fire off saying an item with that configuration already exists. Likewise if they change it to be 003, d, 4, the same message should display.

I have tried joining the tables together, and grouping them, but because the first three rows match for each itemNo, the results are incorrect. The only other option I see is looping through each itemNo and comparing the property and value columns of my user values with each respective in the itemNo table, which could possibly have thousands and thousands of rows.

Any ideas?
[1201 byte] By [bjswift] at [2007-11-20 11:04:19]
# 1 Re: Very advanced query, checking for existing combinations...
Isn't each row different? Just key all three fields, and don't allow dups.
dglienna at 2007-11-9 13:45:30 >
# 2 Re: Very advanced query, checking for existing combinations...
Well, keeping with my example, you should be able to enter values such as:

003, a, 99
003, b, 2
003, c, 3
003, d, 0

OR

003, a, 99
003, b, 2
003, c, 3
003, d, 4

Because the 'a' property has a value (99) different than the other two numbers (001,002) then it will be valid.
bjswift at 2007-11-9 13:46:31 >