I have a table called conversations. Beside that, I have a table called conversation_participants.
When users create a conversation, they pick which other users they want to make it with. I do, tough, want to check before creating a new conversation, that it doesn't already exists with that batch of participants - if so I just want to reuse the existing one.
So my question is. How do I find a row in conversation that has the exact relations in conversation_participants.
My table looks like this (simplified).
| conversations |
| ------------------- |
| id | int (pk) |
| created | timestamp |
| ------------------- |
| conversation_participants |
| ---------------------------------------- |
| id | int (pk) |
| created | timestamp |
| conversation | int (fk to conversations) |
| user | int (fk to users) |
| read | timestamp |
| ---------------------------------------- |
Now the question is. How do I find the row in conversation that has the exact set of users in conversation_participants? It must be the exact set – not just a subset.