sql - Mysql query, get exact value -


i have table 1 i'm trying chat_id members excat match example want chat id members 1,2 when select * member_to_chat member_id in (1,2) returns results , chat number 3, wrong because in chat have 3 people need if give member_id 1 , 2 chat_id 1, possible mysql, thank in advance! , sorry english if it's not good.

member_to_chat

id | member_id | chat_id 1       1          1 2       2          1 ---------------------- 3       1          2 4       3          2 ---------------------- 5       1          3 6       2          3   7       3          3 

the result given member_id 1,2 - chat_id has 1, or if pass 1,2,3 has return chat_id 3, thank again suggesstions

http://sqlfiddle.com/#!9/d7519/3

select distinct chat_id member_to_chat m not exists (select chat_id          member_to_chat          member_id not in(1,2)         , chat_id=m.chat_id) , exists        (select chat_id          member_to_chat          member_id=1) , exists        (select chat_id          member_to_chat          member_id=2) 

sqlfiddle demo


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -