Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 45 - Modular_V2.0_SQL_Flipbook
P. 45

    +----------+------------+-----+
                                                    | 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 WHERE Age > 18 ORDER BY DOB DESC;
                     The above stated query will be sorting the data based on a criteria of age but it will sort that data
                     (DOB) in descending order.

                     Output will be:
                                                    +----------+------------+-----+
                                                    | Stu_name | DOB        | Age |
                                                    +----------+------------+-----+
                                                    | Babita   | 2003-05-18 | 24  |
                                                    +----------+------------+-----+
                                                    | Zara     | 2002-04-01 | 20  |
                                                    +----------+------------+-----+
                                                    | Lalita   | 2001-03-12 | 21  |
                                                    +----------+------------+-----+
                                                    | Amia     | 2000-10-10 | 22  |
                                                    +----------+------------+-----+
                                                    | Raja     | 1999-01-08 | 23  |
                                                    +----------+------------+-----+
                     If you have not specified ASC or DESC after the ORDER BY clause, the ASC is used by default.

                         FUNCTION

                     A function is a set of predefined commands that perform specific operation to return a value to the
                     program. Arguments and parameters are the ways to pass values to the functions.
                     Some of the common functions used in MySQL are as follows:

                        String functions                      Numeric functions                   Date and Time functions

                     String Functions

                     Strings can be handled in many ways in MySQL. Some commonly used string functions are being
                     discussed below:
                      S.No.          Function                      Purpose                          Functionality

                                                                                          SELECT CHAR (70);
                                                      Returns the character for each
                                                                                          Output: F
                         1     CHAR( )                integer value passed as an
                                                                                          SELECT CHAR (65);
                                                      argument
                                                                                          Output: A
                                                      Returns concatenated string         Select CONCAT ("ram", "sham");
                         2     CONCAT( )
                                                      (joins the strings back to back)    Output: ramsham

                                                                                                                         43
                                                                                                        More on MySQL

| 40 41 42 43 44 45 46 47 48 49 50 |