Home > Back-end >  How to get the SQL result in reverse from the columns in SQL
How to get the SQL result in reverse from the columns in SQL

Time:07-19

I have been asked a question in an interview.

Sample table named test:

A|| B
---------- -
1 | a
2 | b
3 | c
4 | d

Desired output:

A || B
------- -
1 | d
2 | c
3 | b
4 | a

How to to get the desired output?

CodePudding user response:

You just need to use order by on column B ASC|DESC

SELECT ROW_NUMBER() over (order by Testcol DESC) as A, B
FROM Table
ORDER BY B DESC;
  •  Tags:  
  • sql
  • Related