Thursday, July 17, 2014

Working with column index number in SQL query

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





No comments:

Post a Comment

Put your comments here

Motivational qoutes

पूरे विश्वास के साथ अपने सपनों की तरफ बढ़ें। वही ज़िन्दगी जियें जिसकी कल्पना आपने की है।