Query sorted- ORDER BY command

 

  • Retrive the details of company database with respect to f_name,last_name and b_date in ascending order.

 

 

SQL> select Fname,Lname,Bdate
  	2     from employee
  	3     order by fname asc;

FNAME                LNAME                BDATE
-------------------- -------------------- ---------
Thilak               naik                 30-AUG-96
Varun                deva                 30-OCT-98
pranav               naik                 01-NOV-92
prjwal               raj                  13-DEC-93

 

 

  • Retrive the details of dependent table in descending order of Fname on  who is depending on and his  name.

 

SQL> select fname,essn
  2     from employee,dependent
  3     where ssn=essn
  4     order by fname desc;

FNAME                ESSN
-------------------- ----------
prjwal               4126
pranav               0662
Varun                0236
Thilak               7894

 

 

  • Retrieve the details of dependent in ascending order of manager’s start date.

 

 

SQL> select *
  2  from department
  3  order by mgrstartdate desc;

DNAME                       DNO     MGRSSN MGRSTARTD
-------------------- ---------- ---------- ---------
Accounts                      1       1234    30-OCT-98
Product                         5       1238    30-JAN-97
Marketing                     3       1237    14-FEB-96
Packing                         4       1236    17-DEC-95
Transport                      2       1235    13-NOV-93
sales                              6       1239    04-MAR-92

 

4.Retrieve the details of the project in desc order of project name.

 

SQL> select *
2    from project
3    order by pname desc;

PNAME                   PNUMBER PLACATION                   DNO
-------------------- ---------- -------------------- ----------
sound system                 126 puttur                   	      5
mobile display               123 mangalore                 	      2
led bulbs                        127 surathkal                    	      1
electronics item             125 mysore                        	      4
battery                           124 hassan                        	      3



 

5.Retrieve book_id,branch_id,no_of_copies of a book in ascending order of  

authors name.

 SQL> select author_name,A.book_id,branch_id,no_copies
  2     from book_authors A,book_copies B
  3     where A.book_id=b.book_id
  4     order by author_name;

AUTHOR_NAME     BOOK_ID    BRANCH_ID             NO_COPIES
--------------- ---------- -------------------- ----------
KUVEMPU         BOOKID01   BRNCHID01                  1400
Krishna                BOOKID05   BRNCHID05                   365
Lakshmi               BOOKID04   BRNCHID04                   254
Ramesh                BOOKID03   BRNCHID02                   800
Tagore                 BOOKID02   BRNCHID03                   100