title: In MySQL check if set of values is equal to the values of another set; don't care about order
body: <p>I'm checking if 2 foreign ids of a table are equal to 2 foreign keys in another table to the same table, but I don't care about the order of the ids, just that they have the same values.</p>
  
  <p>i.e.</p>
  
  <pre><code>SELECT (1, 2, 3) = (1, 2, 3);
  &gt; 1
  
  SELECT (1, 2, 3) = (2, 1, 3);
  &gt; 0
  </code></pre>
  
  <p>I'd like a way so that <code>(1,2,3)</code> matches <code>(2,1,3)</code> as well as <code>(1,3,2)</code> and <code>(2,3,1)</code>.</p>
  
  <p>Unfortunately searching for information on this has proved difficult, most advice is "Lists don't exist in MySQL" and searches for sorting, or unordered checking result in various SQL calls that aren't relevant.</p>
  
  <p>Fiddle: <a href="https://www.db-fiddle.com/f/eqz27tR9uDMQriDhkwBo2a/0" rel="nofollow noreferrer">https://www.db-fiddle.com/f/eqz27tR9uDMQriDhkwBo2a/0</a></p>
  
  <p>I deliberately put an <code>event</code> in the table with the participants ordered differently to the participants in <code>not_event</code>, and it's that join, </p>
  
  <pre><code>SELECT * FROM event
   JOIN not_event ON (
    (event.participant_1_id, event.participant_2_id) =
    (not_event.participant_1_id, not_event.participant_2_id));
  </code></pre>
  
  <p>That's the issue.  I don't care what order <code>participant_1_id</code> and <code>participant_2_id</code> are, in either table, so long as they're the same 2.</p>
  
  <p>Rest of code from fiddle,</p>
  
  <pre><code>CREATE TABLE `participant` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `key` varchar(15) NOT NULL,
    PRIMARY KEY (`id`));
  
  CREATE TABLE `event` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `participant_1_id` int(11) NOT NULL,
    `participant_2_id` int(11) NOT NULL,
    PRIMARY KEY (`id`),
    CONSTRAINT `event_ibfk_1` FOREIGN KEY (`participant_1_id`) REFERENCES `participant` (`id`),
    CONSTRAINT `event_ibfk_2` FOREIGN KEY (`participant_2_id`) REFERENCES `participant` (`id`)
  );
  
  CREATE TABLE `not_event` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `participant_1_id` int(11) NOT NULL,
    `participant_2_id` int(11) NOT NULL,
    PRIMARY KEY (`id`),
    CONSTRAINT `not_event_ibfk_1` FOREIGN KEY (`participant_1_id`) REFERENCES `participant` (`id`),
    CONSTRAINT `not_event_ibfk_2` FOREIGN KEY (`participant_2_id`) REFERENCES `participant` (`id`)
  );
  
  INSERT INTO `participant` VALUES (1, 'Team1');
  INSERT INTO `participant` VALUES (2, 'Team2');
  
  INSERT INTO `event` VALUES (NULL, 1, 2);
  INSERT INTO `not_event` VALUES (NULL, 2, 1);
  
  SELECT (1, 2, 3) = (1, 2, 3);
  SELECT (1, 2, 3) = (2, 1, 3);
  
  SELECT * FROM event
   JOIN not_event ON (
   (event.participant_1_id, event.participant_2_id) =
   (not_event.participant_1_id, not_event.participant_2_id));
  
  
  SELECT * FROM event
   JOIN not_event ON (
   (event.participant_1_id, event.participant_2_id) =
   (not_event.participant_2_id, not_event.participant_1_id));
  </code></pre>