Select with Order by Clause


Select with Order by Clause

select * from <table_name> order by columnname [asc|desc];

Example

I want to see highest salary employee on the top:

select * from employee order by salary desc;

I want to see lowest salary employee on the first one:

select * from employee order by salary;

Note: asc order is default one you not need to specify it.

I want to sort department wise highest salary on top.

select * from employees order by dept_no asc, salary desc ;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s