MySQL | Order By Complete Explanation | The SQL Gym

MySQL | Order By Complete Explanation | The SQL Gym

Thumbnail

Execute following code in MySQL WorkBench, and Let’s start with exercise

create database if not exists tg117;

use tg117;

create table employee(eid int,ename varchar(50),city varchar(20),dept varchar(20),salary float) ;
insert into employee(eid,ename,city,dept,salary) values
(1,'Bahubali','mahishmati','DEV',5.8),
(2,'Munna Bhaiyya', 'mirzapur','HR',3.6),
(3,'Devasena','pune','HR',3.2),
(4,'Bhallaldev','mahishmati','ADMIN',4.1),
(5,'Jethalal','Ahemdabad','SALES',5.2),
(5,'Sunderlal','Ahemdabad','SALES',5.1),
(6,'Atmaram Bhide','pune','HR',4.8);

select * from employee ;

Now Let’s Start with OrderBy Queries :

  1. Select ename,dept,salary from employee ordered by salary (low to high)
    mysql> select ename,dept,salary from employee order by salary ;
    mysql> select ename,dept,salary from employee order by salary asc;
  2. Select ename,dept from employee ordered by salary (low to high)
    mysql> select ename,dept from employee order by salary ;
    mysql> select ename,dept from employee order by salary asc;
  3. Select ename,dept from employee ordered by salary (high to low)
    mysql> select ename,dept,salary from employee order by salary desc;
  4. Select ename,city from employee ordered by city and salary (both asc)
    mysql> select ename,city,salary from employee order by city, salary ;
    mysql> select ename,city,salary from employee order by city asc, salary asc;
  5. Select ename,city,salary from employee ordered by city and salary (both desc)
    mysql> select ename,city,salary from employee order by city desc, salary desc;
  6. Select ename,city from employee ordered by city and salary (city asc, salary desc)
    mysql> select ename,city,salary from employee order by city, salary desc;
    mysql> select ename,city,salary from employee order by city asc, salary desc;
  7. Select ename,city from employee ordered by city and salary (city desc, salary asc)
    mysql> select ename,city,salary from employee order by city desc, salary ;
    mysql> select ename,city,salary from employee order by city desc, salary asc;
Leave your thought here

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

Technological Geeks

The main objective of “TG” family is to provide guidance about the recent technologies to students , beginners and IT professionals .

Contact Us

sdp117@gmail.com
Contact No: 9028378280
New Vishal Nagar, Gajanan Mandir, Garkheda, Aurangabad

Copyright © 2022 | Technological Geeks. All Rights Reserved.

Shopping cart

0

No products in the cart.

Hit Enter to search or Esc key to close