title: Selecting MYSQL column conditionally
body: <p>Example schema for my question is given at <a href="http://sqlfiddle.com/#!2/bbe5b" rel="noreferrer">SQLFiddle</a> and as follow:</p>
  
  <pre><code>CREATE TABLE `players` (
    `player1id` int(11) NOT NULL,
    `player2id` int(11) NOT NULL,
    PRIMARY KEY (`player1id`,`player2id`)
  ) ENGINE=InnoDB;
  
  INSERT INTO `players` values
  (1,5),
  (1,7),
  (5,3),
  (5,4),
  (2,1);
  </code></pre>
  
  <p>In a online game, I want to select opponent, which could be in player <code>player1id</code> or <code>player2id</code>.</p>
  
  <p>Example Input/ output needed</p>
  
  <pre><code>Input 1: Output 5, 7, 2
  Input 5: Output 1, 3 ,4
  &amp; so on.
  </code></pre>
  
  <p>That is, required data could be in any column but I need output in single column conditionally or any other way. I heard about MySQL conditional column but could not create query to get required output. Can someone please help with required query.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Based on <a href="http://forums.mysql.com/read.php?10,6639,6677#msg-6677" rel="noreferrer">this link</a>, I run following query but failed.</p>
  
  <pre><code>SELECT IF(PLAYER1ID IS 1,PLAYER2ID as opponent,PLAYER1ID as opponent) 
  FROM players
  WHERE PLAYER1ID = 1 OR PLAYER2ID = 1;
  </code></pre>