order by clause of SQL

This keyword is used with from clause and it will represent the result in ascending/descending order. in other words, we can say that order by is used to sort records of result alphabetical or numerically. by default values of order by is arranged in ASC .

syntax :- 
select column_name from table_name order by column_name ASC (ascending order) /  DESC (descending order);

example :- 

1. display all the records of table order by customer name.

select * from sells order by Cust_name ASC;

o/p :-
Order_ID
Order_price
Quantity
Cust_name
1
100
2
Aayush
6
425
7
Chetan
5
3000
4
Himanshu
4
1050
3
Kavita
3
287
1
Mayuri
7
210
2
Naved
10
4000
8
Ravi
8
777
NULL
Simran
2
65
4
Tarun

2. display customer name and order name from sells table order by quantity.

i/p :- select Order_ID, Cust_name from sells order by Quantity;

o/p :-

Order ID
Cust_name
3
Mayuri
1
Aayush
7
Naved
4
Kavita
2
Tarun
5
Himanshu
6
Chetan
10
Ravi
9
NULL

No comments:

Post a Comment

Nested SQL Query or SQL Sub Query in hindi in english

if a SQL query is used inside another SQL query then this type of SQL query is called sub-query.  यदि किसी SQL क्वेरी का उपयोग, किसी अन्य SQ...