# Database: Examples: University: Exercises: Simple Selects

Name __________________________________________
These questions all apply to the University database.

1. Print the entire student table.
   Answer:

       SELECT *
           FROM Students;

   or

       SELECT stu_id, stu_fname, stu_lname, stu_gpa
           FROM Students;

   The "*" form is good if you're just taking a look at a table. Naming all fields is generally a better solution if the SQL is coming from a program because (1) you will get the fields in the requested order even if someone changes the table order, (2) you will get the right fields even if someone has added additional fields, and (3) if fields are missing, the SQL request will fail and the program will discover that rather than continue with incorrect data.
2. Print the first and last names of all students.
   Answer:

       SELECT stu_fname, stu_lname
           FROM Students;

3. Print the last name, then first name of all students in ascending alphabetical order The last names should be in alphabetical order, and where two students have the same last name, the first names should be in order.
   Answer:

       SELECT stu_lname, stu_fname
           FROM Students
           ORDER BY stu_lname, stu_fname;

4. Print all the first names in ascending alphabetical order, but do not repeat any names.
   Answer:

       SELECT DISTINCT stu_fname
           FROM Students
           ORDER BY stu_fname;

5. Print the GPA with the last and first names for all students whose GPA is at least 3.0, in the order of descending GPA.
   Answer:

       SELECT stu-gpa, stu_lname, stu_fname
           FROM Students
           WHERE stu_gpa >= 3.0
           ORDER BY stu_gpa DESC;