SQL Order By
Last updated
Last updated
The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.
Below is a selection from the "Consumer" table :
The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" column:
The following SQL statement selects all customers from the "Customers" table, sorted DESCENDING by the "Country" column
The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" and the "Customer Name" column:
The following SQL statement selects all customers from the "Customers" table, sorted ascending by the "Country" and descending by the "Customer Name" column:
Table - Customer
Write a query to display the orders according to the order number arranged by ascending order.
Write a SQL statement to display the customer name, city, and grade, etc. and the display will be arranged according to the smallest customer ID.
Write a SQL statement to make a report with salesman ID, order date and highest purchase amount in such an arrangement that, the smallest salesman ID will come first along with their smallest order date.
Write a SQL statement to display customer name, city and grade in such a manner that, the customer holding highest grade will come first.
Write a SQL statement to arrange the orders according to the order date in such a manner that the latest date will come first then previous dates.