Page 135 - CloudGPT_C8_Flipbook
P. 135

WHERE specifies the criteria according to which rows are retrieved.
                    FROM specifies the table(s) from which to retrieve the data.

                    ORDER BY specifies an 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  |   480 |
                                      |     10003 | Aadarsh   | Kumar    |   475 |
                                      +-----------+-----------+----------+-------+
                 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    |   475 |
                                      +-----------+-----------+----------+-------+

                 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    |   475 |
                                      |     10001 | Amit      | Sharma   |   450 |
                                      |     10002 | Divya     | Kaushik  |   480 |
                                      +-----------+-----------+----------+-------+

                 We can also use the wildcard characters ( _ and %) with the SELECT command alongwith LIKE
                 operator  to specify conditions. The _ wildcard denotes a single character, on the other hand the %
                 wildcard denotes the multiple characters:

                     SELECT FirstName, Marks FROM Student WHERE LastName like ‘K%’;
                                                     +-----------+-------+
                                                     | FirstName | Marks |
                                                     +-----------+-------+
                                                     | Divya     |   480 |
                                                     | Aadarsh   |   475 |
                                                     +-----------+-------+




                                                                                                   MYSQL      133
   130   131   132   133   134   135   136   137   138