Page 29 - 2617_JSSPS_C-8
P. 29

To insert above records, we use the following commands:

                      INSERT INTO Student VALUES (10001, 'Amit', 'Sharma', 450);

                      INSERT INTO Student VALUES (10002, 'Divya', 'Kaushik', 450);

                      INSERT INTO Student VALUES (10003, 'Aadarsh', 'Kumar', 450);

                 RETRIEVING RECORDS FROM TABLE

                 The SELECT command retrieves zero or more rows from a table. It helps us to join information from
                 different tables and filter specific information as per the required criteria. The SELECT command is the
                 most useful DML command. The ‘SELECT’ statement has many optional clauses which are as follows:

                    WHERE specifies the criteria according to which rows are retrieved.
                    ORDER BY specifies the order (Ascending or Descending) to return the rows.

                 The syntax to execute the SELECT queries:

                      SELECT * FROM table_name;
                 To display all the data in the table:

                      SELECT * FROM Student;

                 The preceding command will display the following output:
                                        +-----------+-----------+----------+-------+
                                        | StudentID | FirstName | LastName | Marks |
                                        +-----------+-----------+----------+-------+
                                        |     10001 | Amit      | Sharma   |   450 |
                                        |     10002 | Divya     | Kaushik  |   450 |
                                        |     10003 | Aadarsh   | Kumar    |   450 |
                                        +-----------+-----------+----------+-------+
                 To get details of the list of students whose LASTNAME is Kumar:

                      SELECT * FROM Student WHERE LastName = "Kumar";

                 The preceding command will display the following output:

                                        +-----------+-----------+----------+-------+
                                        | StudentID | FirstName | LastName | Marks |
                                        +-----------+-----------+----------+-------+
                                        |     10003 | Aadarsh   | Kumar    |   450 |
                                        +-----------+-----------+----------+-------+

                 To get details of the list of students in ascending order of FirstName:

                      SELECT * FROM Student ORDER BY FirstName ASC;

                 The preceding command will display the following output:
                                       +-----------+-----------+----------+-------+
                                       | StudentID | FirstName | LastName | Marks |
                                       +-----------+-----------+----------+-------+
                                       |     10003 | Aadarsh   | Kumar    |   450 |
                                       |     10001 | Amit      | Sharma   |   450 |
                                       |     10002 | Divya     | Kaushik  |   450 |
                                       +-----------+-----------+----------+-------+





                                                                                           Introduction to MySQL    27
   24   25   26   27   28   29   30   31   32   33   34