Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

SQL Tutorial

22 / 68

Sorting the query results

By default, select can give rows in any order.

To get the data in order by certain columns, use 'order by'.

Syntax:

select field1, field2,...fieldN table_name1, table_name2...
order by field1, [field2...] [asc[desc]]

select * from deptt order by depcity asc,depstreet desc;

Sorting columns in 'order by' can also be referred to by column position in the 'select' expression rather than actual column names.

In below example, the result will be sorted by 2nd and 5th columns of the output.

select * from deptt order by 2,5;

No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...