Page 167 - Informatics_Practices_Fliipbook_Class12
P. 167

Executing the above statement will produce output shown in Table 4.15. Note that the table appears in descending
            order of Salary. However, due to the ORDER BY clause's default setting (ascending order), the employees having
            the same salary are arranged in ascending order of their last name (LNAME).

                                      ID          FName            LName            Salary
                                    10004          Hiten           Oberoi           100000

                                    10001           Raj             Reddy           100000
                                    10003         Muskaan          Taneja           100000
                                    10005          Anshul          Verma            100000
                                    10002          Dhiraj           Bora            85000
                                    10007          Taran           Adarsh           70000
                                    10008          Naval           Dhingra          70000

                                    10009         Naveen            Basra           60000
                                    10006           Rajit           Gadh            60000
                                    10010          Savita         Ambedkar          50000
                   Table 4.15 Salary in descending order, LName in ascending order for the employees having the same salary

            4.4.12 BETWEEN Operator

            The BETWEEN operator checks whether a  value is within a specified range (inclusive of both lower limit and upper limit
            values). It may be applied to numbers, text, and dates. Syntax of an SQL query using  BETWEEN operator is given below:

                   SELECT attribute1, [attribute2, …]
                   FROM table_name
                   WHERE attributeJ [NOT] BETWEEN value1 AND value2;
            The above WHERE clause serves as an abbreviation for the following clause:
                   WHERE [NOT](attributeJ >= value1 AND attributeJ <= value2);

            To display ID, FName, and Salary of those employees whose salary is between 85000 to 100000, both inclusive,
            we may use the following query:
                   SELECT ID, FName, Salary

                   FROM EMPLOYEE
                   WHERE Salary BETWEEN 85000 AND 100000;
            Table 4.16 displays the output of the given query.

                                              ID          FName            Salary

                                             10001          Raj            100000
                                             10002         Dhiraj          85000

                                             10003        Muskan           100000
                                             10004         Hiten           100000

                                             10005        Anshul           100000
                                      Table 4.16 Employees having salary between 85000 and 100000

            Note that Table 4.16 includes salary 85000 and 100000, specified for the BETWEEN operator. Thus, BETWEEN is an
            inclusive operator as it includes the begin and end values of the specified range.



                                                                                        Database Query using SQL  153
   162   163   164   165   166   167   168   169   170   171   172