To return sorted records from SQL Server database table, we use
BY followed by column name to sort and
ASC (for ascending order) and
DESC (for descending order) keywords.
If ASC or DESC is not specicied, ASC is treated by default.
SELECT PersonalDetailsId, FirstName, LastName, Age, Active FROM PersonalDetails ORDER BY Age
Above query would sort all records from the
PersonalDetails table based on
Age column value in ascending order. Notice that we have not mentioned ASC or DESC after ORDER BY Age column as by default its ascending order.
See following query
SELECT PersonalDetailsId, FirstName, LastName, Age, Active FROM PersonalDetails ORDER BY Age DESC
DESC keyword in the last, will sort records based on
Age column in descending order.
Views: 2431 | Post Order: 46