database - MySQL question for conversation app -


i have app manages conversations between users on website. 1 one conversations having multiple people in single conversation.

here layout mysql tables

conversations
conversations_meta

the conversations_meta table links users conversations logging user_id , conversation_id. holds meta info conversation specific each user in conversation.

what having trouble detecting if conversation same people exist. example if conversation between eric jason , bob exists maybe it's old , user forgot , tries create addition conversation same users notify them of conversation.

so query should in conversations_meta table , compare user_id , conversation_id see if same conversation exists already. wouldn't want return conversations include same users , additional users well. main reason posted question on here fastest query possible accomplish task since there thousands of conversations.

what this:

select conversations_meta.conversations_id conversations_meta   (conversations_meta.user_id=1) or (conversations_meta.user_id=2) group conversations_id having count(*) = 2  

note: case 2 people in conversation. expanded case of 3 or or more.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -