Up: Sorting

Exercises

Getting Started

In these exercises we will be using a database of that contains information about Nobel Prizes:  nobel_prizes.sqlite. We’ve put up instructions on how to use SQL Manager for Firefox to interact with this database.

The exercises

  1. Fetch all of the prizes, and sort them by Year.
    (Click for our answer)
    SELECT * FROM Nobel_Prizes ORDER BY Year;

    You may have chosen to specify ASC or DESC after the Year column as well, like so:

    SELECT * FROM Nobel_Prizes ORDER BY Year DESC;

  2. Fetch all of the prizes, and sort them by Area in descending order, and within each area sort by Year in ascending order.
    (Click for our answer)
    SELECT * FROM Nobel_Prizes
    ORDER BY Area DESC, Year ASC;
  3. Fetch all of the Nobel Prizes awarded in or before 1950 and sort the results by the Area.
    (Click for our answer)
    SELECT * FROM Nobel_Prizes
    WHERE Year <= 1950
    ORDER BY Area;

    Notice that we put the ORDER BY clause after the WHERE clause. In SQL, the different clauses have to appear in a certain order. We’ll discuss this again in a future lecture.

    Check out the solution walkthrough screencast:


  1. June 20th, 2010 at 06:28 | #1

    Great number of interactive exercises you can find on SQL Exercises: http://www.sql-ex.ru/. Test your SQL skills.

  1. No trackbacks yet.