SQL server is the most popular database of microsoft company which was develop in 1989. SQL stands for Structure Query Language. It is RDBMs so in this case record is store in tabular format. It is platform dependent because it runs only on windows operating system.

ORDER BY CLAUSE WITH ASCENDING ORDER

Ascending order is use to sort data in ascending order. SQL ORDER BY query takes ascending order by default is knows as Ascending order statement in SQL

Syntax

SELECT ColumnName1,...,ColumnNameN FROM TableName  ORDER BY ColumnName ASC; 

Example of ORDER BY CLAUSE WITH ASCENDING ORDER

SELECT * FROM test.person2
order by Name;
Input value of Ascending order

Output of ORDER BY CLAUSE WITH ASCENDING ORDER

Output value of Ascending order

ORDER BY CLAUSE WITH DESCENDING ORDER

Descending order statement is use to sort data in descending order. You should use the DESC attribute in your ORDER BY clause is knows as Descending order in SQL

Syntax

  

SELECT ColumnName1,...,ColumnNameN FROM TableName  ORDER BY ColumnNameDESC;  

Example of ORDER BY CLAUSE WITH DESCENDING ORDER

SELECT * FROM test.person2
order by Name DESC;
Input value of descending order

Output of ORDER BY CLAUSE WITH DESCENDING ORDER

Output value of descending order

ORDER BY CLAUSE WITH RANDOM ORDER

It is use to sort records in random order in SQL Server is knows as Random order in SQL

Syntax

SELECT column FROM table ORDER BY RAND () LIMIT 1 

Example of ORDER BY CLAUSE WITH RANDOM ORDER

SELECT Name FROM test.person2
order by rand() limit 1;
Input value RANDOM ORDER

Output of ORDER BY CLAUSE WITH RANDOM ORDER

Output value RANDOM ORDER

ORDER BY CLAUSE WITH LIMIT ORDER

Syntax

SELECT * FROM table_name limit ;

Example of ORDER BY CLAUSE WITH LIMIT ORDER

SELECT * FROM test.student_details limit 5;
Input value of order by clause with Limit order

Output ORDER BY CLAUSE WITH LIMIT ORDER

Output value of order by clause with Limit order

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about SQL please Wikipedia click here .

Stay Connected Stay Safe, Thank you


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *