I am a SQL newbie and here is a question that I cannot find a solution yet.
Say I have tables User
and Partner
. I want to have a composite key for Partner
, which is a pair of User
's. So I can have keys (A,B) and (B,A) where A and B are both users. I want to have that (A,B) and (B,A) refer to the same Partner
entity. This seems to be a common problem but I could not find an answer.
Ok, more concretely,
CREATE TABLE User
(
ID int,
....
)
PRIMARY KEY (ID);
CREATE TABLE Partner
(
User1 UserID,
User2 UserID
...
)
PRIMARY KEY (User1, User2)
What I want is that (User1, User2) and (User2, User1) represent the same partnership.