Sometimes we have the question in our mind that how to get data from SQL table in sorted order by retriving by column index instead of column name. Generally this can be done when we use nested query and table name is given temporarily.
we can use column index in the select query to get the output. This can be done only for sorting the data from any table.
For example we have an employee table with this records
To sort the data in descending order by column name "EmpCode" we have the query
Select * from Emp order by EmpCode desc
To sort the data in descending order by column index of "EmpCode" we have the query
Select * from Emp order by 2 desc
result from both the queries given above is
we can use column index in the select query to get the output. This can be done only for sorting the data from any table.
For example we have an employee table with this records
To sort the data in descending order by column name "EmpCode" we have the query
Select * from Emp order by EmpCode desc
To sort the data in descending order by column index of "EmpCode" we have the query
Select * from Emp order by 2 desc
result from both the queries given above is
No comments:
Post a Comment
Put your comments here