title: Swap two adjacent rows of a column in sql
body: <p>I'm trying to solve this following problem:</p>
  
  <p>Write a sql query to swap two adjacent rows in a column of a table.</p>
  
  <p><strong>Input table</strong></p>
  
  <pre><code>Name  Id
   A    1
   B    2
   C    3
   D    4
   E    5
  </code></pre>
  
  <p><strong>Output table</strong></p>
  
  <pre><code>Name  Id
   A    2
   B    1
   C    4
   D    3
   E    5
  </code></pre>
  
  <p>Description:- 1 is associated with A and 2 with B, swap them, thus now 1 is associated with B and 2 with A, Similarly do for C and D, Since E doesn't has any pair, leave it as it is.</p>
  
  <p>Note:- This may be solved using CASE Statements, but I am trying for a generalized solution, Say currently it is only 5 rows, it may be 10,20 etc..</p>
  
  <p>Eg: </p>
  
  <pre><code>SELECT
  *,CASE WHEN Name = A then 2 ELSEIF Name = B then 1 etc...
  FROM YourTable
  </code></pre>