डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

Full Stack Web Development with Laravel

Full Stack Web Development with Laravel

Affiliate Program

Affiliate Program

MYSQL ORDER BY ASC DESC

ORDER BY keyword is used to sort records in the form of ascending or descending.

For the ORDER BY command, we will use this given table as an example.

Table: users
id username age country
1 Aman 20 India
2 John 20 USA
3 Ahmad 20 Pakistan


ORDER BY (ASC)

This command will fetch all the records from a table by sorting specified field values in ascending order.

SELECT * FROM users ORDER BY country ASC;
Table: users
id username age country
1 Aman 20 India
3 Ahmad 20 Pakistan
2 John 20 USA

 

ORDER BY (DESC)

This command will fetch all the records from a table by sorting specified field values in descending order.

SELECT * FROM users ORDER BY country DESC;
Table: users
id username age country
2 John 20 USA
3 Ahmad 20 Pakistan
1 Aman 20 India


 

© 2016 - 2023, All Rights are Reserved.