I have a MySQL table as follows:
+----+--------+---------+
| id | userid | otherid |
+----+--------+---------+
| 1 | 1 | 2 |
| 2 | 1 | 3 |
| 3 | 3 | 5 |
+----+--------+---------+
I don't want the pairing of userid and otherid to reappear in the table either way round. So for example the following inserts should not appear in the table:
INSERT INTO users (userid, otherid) VALUE ('2', '1');
INSERT INTO users (userid, otherid) VALUE ('1', '3');
INSERT INTO users (userid, otherid) VALUE ('3', '5');
What do I include in the INSERT to stop these inserts? Or do I have to do a separate SELECT query first? I know you can pair unique columns, but this won't reject the INSERTS above.