Page 162 - iPrime_V2.2_class7
P. 162

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

                  We  can  also  us  the  wildcards  (*  and  %)  with  the  SELECT  command  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 |
                                                      +-----------+-------+
                      SELECT Marks FROM Student WHERE FirstName like 'A%';
                                                              +-------+
                                                              | Marks |
                                                              +-------+
                                                              |   450 |
                                                              +-------+









                 160     Touchpad iPRIME (Ver. 2.2)–VII
   157   158   159   160   161   162   163   164   165   166   167