title: check if an array of users match exist as entries in a linking table with a matching column
body: <p>I have a Channels table with the following structure:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `channels` (
  `ID` int(20) NOT NULL,
    `Name` varchar(50) NOT NULL,
    `creatorID` int(11) NOT NULL,
    `dateCreated` int(20) NOT NULL,
    `isRead` tinyint(4) NOT NULL
  ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
  
  
  INSERT INTO `channels` (`ID`, `Name`, `creatorID`, `dateCreated`, `isRead`) VALUES
  (1, 'chat', 260, 1456307705, 1),
  (2, 'chat2', 36, 1456326568, 0),
  (3, 'chat3', 260, 1456737864, 1);
  </code></pre>
  
  <p>I then have a userChannels table that lists all the members who have been invited into each channel. This is of the following format:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `userchannels` (
  `ID` int(11) NOT NULL,
    `userID` int(11) NOT NULL,
    `channelID` int(11) NOT NULL
  ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
  
  INSERT INTO `userchannels` (`ID`, `userID`, `channelID`) VALUES
  (1, 36, 1),
  (2, 260, 1),
  (3, 36, 2),
  (4, 1657, 2),
  (5, 1657, 3),
  (6, 260, 3);
  </code></pre>
  
  <p>I am creating a web service to check if the the users passed up in a webservice to be members in this channel already exist in a previous channel. So if they already exist, I will pass back the existing ChannelID and if not, I will create a new channel and add the entries. </p>
  
  <p>So if I were to pass up the user ids of 36 and 260, I should not create a new channel and instead, I should pass back the channelID of 1 as per test data provided. But if I were to pass up 36, 260 and 1657, I would need to create a new entry in the channels' table as there is no current instance of all 3 users existing in one channel.</p>
  
  <p>So I am wondering what is the best way to check if the users passed up already exist in a channel?</p>
  
  <p>I think I may have to make use of group by in the userChannels table and build A Dynamic query?  But I'm really not sure how to implement this.</p>
  
  <p>So far all I have is :</p>
  
  <pre><code>SELECT * FROM `userchannels` 
  WHERE userID = ? or userid = ? group by channelID
  </code></pre>
  
  <p>This is returning unique channels. I guess I will need to build this query dynamically to keep adding userid = ? depending on the length of the array of users passed up in the web service. But I can't see where to go from here. Any help appreciated.</p>