I have a fairly complex database question to ask so I shall try and explain is as verbosely as possible.
I have one table called TypeAttributes.
typeID, attributeID, valueINT
From this table I wish to extract a certain type with a set of 6 attribute ID’s.
So, I wish to end up with something like this from a query searching for typeID, in the below case typeID = 11446
typeID, attributeID, valueINT
11446 182 3000
11446 183 3001
11446 184 3002
11446 277 5
11446 278 2
11446 279 2
From this information, I wish to then run the above query again, but with the valueINT of attributeID’s 182, 183 and 184 as the typeID to query. So, then I should end up with a table look like this:
typeID, attributeID, valueINT
11446 182 3000
11446 183 3001
11446 184 3002
11446 277 5
11446 278 2
11446 279 2
3000 182 1000
3000 183 1001
3000 277 5
3000 278 5
3001 182 51951
3001 277 3
3002 182 1000
3002 277 2
In the end, what I’m hoping to have is all of the prerequisite typeID’s, 182 attribute values (which is actually a type of attribute im interested in),along side its secondary attribute (277).
From this data I should then be able to build a hierarchy of information simply from one item type. IE. I choose item type 11446, and it keeps going through the tree until there are no requisites.
Can this be done entirely in SQL to output a table like this?
I hope this makes some sense to someone.
Kind regards
PS.
As a side note, the attribute ID ties into another table which tells me which kind of attribute im looking at and the value is the value of that attribute, in this case, valueINT is actually another typeID I wish to lookup via the exact same process.
182, 183 and 184 are certain types and 277, 278 and 279 and multipliers of those types.
You want to consider using a method called modified preorder traversal to store tree structured data – this method lets you easily find all nodes which a children of a given node to any depth in a single query.
It seems you have several trees each defined by a particular attribute. Each of these attributes would be replaced by a pair of values to store a left and right node identifier.