unique pair in a “friendship” database

I'm posting this question which is somewhat a summary of my other question.

I have two databases:
1) db_users.
2) db_friends.

I stress that they're stored in separate databases on different servers and therefore no foreign keys can be used.

In 'db_friends' I have the table 'tbl_friends' which has the following columns:
- id_user
- id_friend

Now how do I make sure that each pair is unique at this table ('tbl_friends')?
I'd like to enfore that at the table level, and not through a query.

For example these are invalid rows:
1 - 2
2 - 1

I'd like this to be impossible to add.

Additionally - how would I seach for all of the friends of user 713 while he could be mentioned, on some friendship rows, at the second column ('id_friend')?

6
задан Community 23 May 2017 в 12:08
поделиться