Example schema for my question is given at SQLFiddle and as follow:
CREATE TABLE `players` (
`player1id` int(11) NOT NULL,
`player2id` int(11) NOT NULL,
I think you may use case when then
syntax as below:
SELECT CASE WHEN player1id = 1 THEN player2id ELSE player1id END
FROM players WHERE player1id =1 OR player2id=1;
Alternatively:
SELECT CASE WHEN player1id = 1 THEN player2id WHEN player2id =1 THEN player1id END
FROM players WHERE player1id =1 OR player2id=1;