Page 166 - Informatics_Practices_Fliipbook_Class12
P. 166
On executing the above statement, SQL will produce output shown in Table 4.13. Note the ORDER BY clause's
default setting (ascending order) for the attribute FName.
ID FName
10005 Anshul
10002 Dhiraj
10004 Hiten
10003 Muskan
10008 Naval
10009 Naveen
10001 Raj
10006 Rajit
10010 Savita
10007 Taran
Table 4.13 ID, FName for employees in ascending order of FName
To display ID, first name, and the Salary of all employees ordered by their Salary in descending order, the following
query may be used.
SELECT ID, FName, Salary
FROM EMPLOYEE
ORDER BY Salary DESC;
On executing the above statement, SQL will produce output shown in Table 4.14.
ID FName Salary
10001 Raj 100000
10003 Muskan 100000
10004 Hiten 100000
10005 Anshul 100000
10002 Dhiraj 85000
10007 Taran 70000
10008 Naval 70000
10009 Naveen 60000
10006 Rajit 60000
10010 Savita 50000
Table 4.14 ID, FName, Salary in descending order of Salary
We can also display the records arranged according to the values of two or more attributes in a table. For example, to
display ID, first name, last name, and the Salary of all employees ordered by their Salary in descending order. Further,
for the two employees having the same salary, the tuples must appear in the ascending order of their last names.
SELECT ID, FName, Lname, Salary
FROM EMPLOYEE
ORDER BY Salary DESC, LName;
152 Touchpad Informatics Practices-XII

