Page 44 - Modular_V2.0_SQL_Flipbook
P. 44
+-------------+--------------+
| Designation | Total_salary |
+-------------+--------------+
| VP | 200000 |
+-------------+--------------+
| Manager | 150000 |
+-------------+--------------+
| Clerk | 20000 |
+-------------+--------------+
Clickipedia
The contrast between WHERE and HAVING clause is that WHERE works on the entire table
whereas HAVING clause works on a group. If WHERE and HAVING both are used in a command
WHERE will be given priority in execution.
USING ORDER BY
The ORDER BY keyword is used to sort the values in ascending or descending order.
Consider the following command and the table it refers to:
Table-STUDENTS
Stu_id Stu_name Subject_group DOB Age
101 Amia Arts 2000-10-10 22
102 Raja Commerce 1999-1-08 23
103 Lalita Arts 2001-3-12 21
104 Zara Science 2002-4-01 20
105 Babita Science 2003-5-18 24
SELECT Stu_name, DOB, Age FROM STUDENTS ORDER BY Stu_name DESC;
The above command shows the names of students in descending order. DESC keyword is required here.
Output shall be:
+----------+------------+-----+
| Stu_name | DOB | Age |
+----------+------------+-----+
| Zara | 2002-04-01 | 20 |
+----------+------------+-----+
| Raja | 1999-01-08 | 23 |
+----------+------------+-----+
| Lalita | 2001-03-12 | 21 |
+----------+------------+-----+
| Babita | 2003-05-18 | 24 |
+----------+------------+-----+
| Amia | 2000-10-10 | 22 |
+----------+------------+-----+
SELECT Stu_name, DOB, Age FROM STUDENTS ORDER BY Stu_name DESC, Age ASC;
The above command shows the names of students in descending order. DESC keyword is required
here and age will be sorted in ascending order whenever the name of two students are same. Since
no two names are same here the result will be same as above.
42
Touchpad MODULAR (Ver. 2.0)

