I have an Entity called Status which (among other things) has a many-to-many relationship to itself representing the “Possible Next Statuses”.
The idea is to be able to create a ‘map’ of transitions between statuses.
Now, I’m trying to produce a list of Statuses that aren’t already linked to a given Status to populate a combo box in the “link to this Status” form (in other words, I want those statuses that COULD be linked).
So far, I’ve found 25 ways NOT to do this. 🙂
Ok, so a lot of people are asking for more details – I thought some things are taken for granted in terms of reasonable database design (and they don’t actually matter for the answer).
a) All statuses have one and only one KEY column, their Primary Key.
b) Statuses are ‘connected’ to one another by means of a join table, which has 2 foreign keys, both being the primary key of a status.
c) If I have statuses A, B, C, and D – and I’ve already ‘linked’ statuses B and C to A so I have: A -> B and A -> C the purpose is to find those Statuses existing in Status table, that aren’t yet connected to ‘A’. When I say ‘A’ I mean a status given as a parameter. So, if I was looking at Status A, I want all those not connected to ‘A’. If I was looking at Status C I would want all those not connected to status C regardless if they are connected to a different status.
Any help would be appreciated.
I am not looking for an exact query word by word, I am looking for ‘the way it can be done’. I’ll easily figure out how to apply the principle on my particular DB design, but I was unable to find the ‘principle’ to apply.
1 Answer