You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND m.TourneyPlayer1ID = ) UNION (SELECT m.id, p1.Tag as `player1`, p...' at line 16