SQL with Jupyter Notebook Tutorial

22 / 61

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]]

Example:

%%sql
select * from deptt_<<your lab username>> 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.

%%sql
select * from deptt_<<your lab username>> order by 2,3;

No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...